public int Delete(Expression <Func <T, bool> > whereExpression) { using (var context = GetContext()) { OnDataChanged?.BeginInvoke(this, new DataChangedEventArgs <T>(ChangedTypes.Deleted), null, null); return(context.Set <T>().Where(whereExpression).Delete()); } }
public int Insert(T entity) { using (var context = GetContext()) { OnDataChanged?.BeginInvoke(this, new DataChangedEventArgs <T>(ChangedTypes.Inserted), null, null); context.Set <T>().Add(entity); return(context.SaveChanges()); } }
public IEnumerable <T> Insert(IEnumerable <T> entities) { using (var context = GetContext()) { OnDataChanged?.BeginInvoke(this, new DataChangedEventArgs <T>(ChangedTypes.Inserted), null, null); context.Set <T>().AddRange(entities); var result = context.SaveChanges(); if (result > 0) { return(entities); } return(null); } }
/// <summary> /// 处理订阅事件 /// </summary> /// <param name="item"></param> /// <param name="e"></param> private void OnMonitoredNotification(MonitoredItem item, MonitoredItemNotificationEventArgs e) { MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification; var node = e.NotificationValue as NodeId; var opcUaDataItem = this.OpcUaDataItems.FirstOrDefault(a => a.Name == item.ResolvedNodeId.ToString()); if (!Equals(opcUaDataItem, null)) { opcUaDataItem.OldValue = opcUaDataItem.NewValue; opcUaDataItem.NewValue = notification?.Value.Value; opcUaDataItem.OpcUaStatusCodes = (OpcUaStatusCodes)notification?.Value.StatusCode.Code; OpcUaDataEventArgs args = new OpcUaDataEventArgs(opcUaDataItem.OpcUaStatusCodes, opcUaDataItem); OnDataChanged?.BeginInvoke(this, args, new AsyncCallback((a) => { if (a.IsCompleted) { OnDataChanged?.EndInvoke(a); } }), null); } }