null exception
2番目の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;
}