2

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;
}
4

1 回答 1

1

原来接收 DTO 应该允许一个空值,但不是。

该物业,

Commz.Site_id被宣布:

public int Site_id { get; set; }

并且应该被声明为:

public int? Site_id { get; set; }
于 2013-01-04T20:59:16.580 回答