您好我想基于其主键查询表.
我试过了两个
var deviceDetails = (from d in db.Devices where d.DeviceId == pointDetails.DeviceId select d).ToList();
编辑d.DeviceId
var deviceDetails = db.Devices.Single(d => d.DeviceId == pointDetails.DeviceId)
我知道这些会返回不同的类型,但现在这不是问题.
这个语句抛出一个invalidCastException,我不知道为什么.PointDetails.DeviceId绝对是一个有效的int.即使我用硬编码的int替换它,也会引发异常.
这是堆栈跟踪的相关部分.
at System.Data.SqlClient.SqlBuffer.get_Int32() at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i) at Read_Device(ObjectMaterializer`1 ) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
任何帮助都是因为我没有想法.
类定义和模式 这是Device的类定义
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Devices")] public partial class Device : INotifyPropertyChanging, INotifyPropertyChanged { private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); private int _DeviceId; private int _DeviceTypeId; private string _DeviceName; private string _DeviceMACAddress; private string _DeviceIPAddress; private string _DeviceSubnetMask; private string _DeviceGatewayAddress; private int _ZoneId; private int _TelevisionTypeId; private int _DeviceStatusId; private byte _DeviceIsModified; private int _DeviceSetupBaudRate; private int _DeviceConfigId; private byte _DeviceSetupIsInputInternalPower; private int _DeviceBedSensorInput; private int _DeviceEnsuiteSensorInput; private int _DeviceRoomSensorInput; private string _DeviceSetupString1; private string _DeviceSetupString2; private string _DeviceSetupString3; private string _DeviceSetupString4; private byte _DeviceSetupIsWiegand; private int _DeviceSetupOptionId; private byte _DeviceSetupIsLightMomentary; private string _DeviceTestDateTime; private string _DeviceTestResults;
这是SQL设计
编辑识别导致故障的列
我一次选择了一个colmun来找到导致转换异常的一个colmun,它是DeviceStatusId.对SQL中的tinyInt类型有什么限制?任何建议使这个正确投射