EF常用的添加和修改数据


if (typeof(T) == typeof(PLC_CommunicationData) || typeof(T) == typeof(PLCDeviceInfo))
{
  using (var context = new TuniSettingDataContext())
  {

    if (Exist(entity))
    {
      context.Entry(entity).State = EntityState.Modified;
    }
    else
    {
      context.Entry(entity).State = EntityState.Added;
    }
    return context.SaveChanges() > 0;
  }
}

相关