开发者

LINQ join producing null reference error suddenly

开发者 https://www.devze.com 2023-03-08 10:25 出处:网络
I have a LINQ que开发者_Python百科ry which has the below joins join v in dc.Vehicles on c.VehicleReg equals v.VehicleReg into vg

I have a LINQ que开发者_Python百科ry which has the below joins

join v in dc.Vehicles on c.VehicleReg equals v.VehicleReg into vg
from v in vg.DefaultIfEmpty()
join vt in dc.VehicleTypes on v.VehicleType equals vt.ID into vtg
from vt in vtg.DefaultIfEmpty()

Now this worked perfect before, but it seems all of a sudden it's returning an object reference error trying to join vehicle into vehicletype when v is null. This worked before, and had the effect of making vtg null - which is ideal.

Any ideas?


The simple answer would probable filter null Vehicles

join v in dc.Vehicles.Where(v => v != null) on c.VehicleReg equals v.VehicleReg into vg

Hope that helps

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号