an expression tree lambda may not contain a null propagating operator

前端 未结 4 1946
眼角桃花
眼角桃花 2020-11-28 10:49

Question: The line price = co?.price ?? 0, in the following code gives me the above error. but if I remove ? from co.?

4条回答
  •  感情败类
    2020-11-28 11:18

    The code you link to uses List. List implements IEnumerable but not IQueryable. In that case, the projection is executed in memory and ?. works.

    You're using some IQueryable, which works very differently. For IQueryable, a representation of the projection is created, and your LINQ provider decides what to do with it at runtime. For backwards compatibility reasons, ?. cannot be used here.

    Depending on your LINQ provider, you may be able to use plain . and still not get any NullReferenceException.

提交回复
热议问题