在第二个Select语句中获得一个神秘的null exception
。
public static string GetSNFromDeviceMacAddress(string macAddress)
{
string commzSerialNumber = null;
var dbFactory = EndpointHost.AppHost.TryResolve<IDbConnectionFactory>();
try
{
OrmDataLib.Device device;
OrmDataLib.Commz commz;
using (var db = dbFactory.OpenDbConnection())
{
// first select works fine
device = db
.Select<OrmDataLib.Device>(q => q.MacAddress == macAddress)
.FirstOrDefault();
if (null != device)
{
// mysterious null exception
commz = db
.Select<OrmDataLib.Commz>(c => c.Id == device.Commz_Id)
.FirstOrDefault();
if (null != commz)
commzSerialNumber = commz.SerialNumber;
}
}
}
catch { }
return commzSerialNumber;
}
答案 0 :(得分:1)
原来接收DTO应该允许空值而不是。
财产,
Commz.Site_id
被宣布:
public int Site_id { get; set; }
应该被声明为:
public int? Site_id { get; set; }