Maj*_*jid 2 .net c# linq null reference
我有Room和BedEF类,每个Room都有一些Beds.when我使用这个LINQ语句:
IEnumerable<Room> room=...
if (room == null || !room.Any())
return null;
return room.SelectMany(r=>r.Beds);
Run Code Online (Sandbox Code Playgroud)
给我这个错误:
你调用的对象是空的.
在return行.
YK1*_*YK1 15
可枚举中的一个房间是null.做这个:
return room.Where(r => r != null)
.SelectMany(r => r.Beds);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3369 次 |
| 最近记录: |