null exception
在第二个 Select 语句中得到一个神秘的东西。
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;
}