开发者

Linq Expression returning null rather than empty set

I am finding this weird issue. When I do this >

ac开发者_高级运维tivities.Where(Function(a) (Not a.IsDeleted And a.ParentId = 100)

It returns an in-memory query & when I try opening it up, it throws a object not set exception. This only happens when there were no items which satisfied the condition. Shouldn't it be returning an empty set?

When there are items satisfying the condition, then it returns a list & works all good.

Any ideas?


It looks like you might be getting bitten by using the logical And. You probably meant AndAlso to short-circuit your logical expression:

Not a.IsDeleted AndAlso a.ParentId = 100

By using AndAlso the second part will only be evaluated if the first part is true.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜