EF常用的添加和修改数据

minute_5

关注

阅读 64

2023-06-06

if (typeof(T) == typeof(PLC_CommunicationData) || typeof(T) == typeof(PLCDeviceInfo))
                {
                      using (var context = new TuniSettingDataContext())
                      {                            if (Exist<T>(entity))
                            {
                                  context.Entry<T>(entity).State = EntityState.Modified;
                            }
                            else
                            {
                                  context.Entry<T>(entity).State = EntityState.Added;
                            }
                            return context.SaveChanges() > 0;
                      }
                }

精彩评论(0)

0 0 举报