diff --git a/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceVM.cs b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceVM.cs index fafff7c..96f977b 100644 --- a/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceVM.cs +++ b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceVM.cs @@ -23,7 +23,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVMs protected override void InitVM() { AllDrivers = DC.Set().GetSelectListItems(Wtm, y => y.FileName); - AllParents = DC.Set().Where(x=>x.DeviceTypeEnum== DeviceTypeEnum.Group).GetSelectListItems(Wtm, y => y.DeviceName); + AllParents = DC.Set().Where(x => x.DeviceTypeEnum == DeviceTypeEnum.Group).GetSelectListItems(Wtm, y => y.DeviceName); } public override void DoAdd() @@ -36,7 +36,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVMs { var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService; deviceService.DrvierManager.AddConfigs(this.Entity.ID, this.Entity.DriverId); - var device = DC.Set().Where(x => x.ID == Entity.ID).Include(x=>x.Parent).Include(x => x.Driver).SingleOrDefault(); + var device = DC.Set().Where(x => x.ID == Entity.ID).Include(x => x.Parent).Include(x => x.Driver).Include(x => x.DeviceVariables).SingleOrDefault(); deviceService.CreateDeviceThread(device); var myMqttClient = Wtm.ServiceProvider.GetService(typeof(MyMqttClient)) as MyMqttClient; diff --git a/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/DeviceVariableListVM.cs b/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/DeviceVariableListVM.cs index 01753af..20759f5 100644 --- a/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/DeviceVariableListVM.cs +++ b/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/DeviceVariableListVM.cs @@ -116,7 +116,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs var threadDeviceIds = deviceService?.DeviceThreads.Select(x => x.Device.ID).Distinct(x => x); //设备线程中的变量 var threadVariables = - deviceService?.DeviceThreads.SelectMany(deviceThread => deviceThread.Device.DeviceVariables); + deviceService?.DeviceThreads.Where(x => x.Device.DeviceVariables != null).SelectMany(deviceThread => deviceThread.Device.DeviceVariables); //查找数据库中额外的变量 var dcVariables = DC.Set().AsNoTracking().Include(x => x.Device) .Where(x => !threadDeviceIds.Contains((Guid)x.DeviceId)).AsEnumerable(); @@ -127,30 +127,30 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs { var ids = UpdateDevices.FC2Guids(FC); - return variables.Where(x=> ids.Contains(x.ID)).Select(x => new DeviceVariable_View - { - ID = x.ID, - DeviceId = x.DeviceId, - Name = x.Name, - Index = x.Index, - Description = x.Description, - Method = x.Method, - DeviceAddress = x.DeviceAddress, - DataType = x.DataType, - IsTrigger = x.IsTrigger, - EndianType = x.EndianType, - Expressions = x.Expressions, - IsUpload = x.IsUpload, - ProtectType = x.ProtectType, - DeviceName_view = x.Device.DeviceName, - Alias = x.Alias, - Device = x.Device, - Value = x.Value, - CookedValue = x.CookedValue, - StatusType = x.StatusType, - Timestamp = x.Timestamp, - Message = x.Message, - }) + return variables.Where(x => ids.Contains(x.ID)).Select(x => new DeviceVariable_View + { + ID = x.ID, + DeviceId = x.DeviceId, + Name = x.Name, + Index = x.Index, + Description = x.Description, + Method = x.Method, + DeviceAddress = x.DeviceAddress, + DataType = x.DataType, + IsTrigger = x.IsTrigger, + EndianType = x.EndianType, + Expressions = x.Expressions, + IsUpload = x.IsUpload, + ProtectType = x.ProtectType, + DeviceName_view = x.Device.DeviceName, + Alias = x.Alias, + Device = x.Device, + Value = x.Value, + CookedValue = x.CookedValue, + StatusType = x.StatusType, + Timestamp = x.Timestamp, + Message = x.Message, + }) .OrderBy(x => x.Index).ThenBy(x => x.DeviceName_view).ThenBy(x => x.Alias).ThenBy(x => x.Method) .ThenBy(x => x.DeviceAddress); }