an expression tree lambda may not contain a null propagating operator

前端 未结 4 1947
眼角桃花
眼角桃花 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:17

    Jon Skeet's answer was right, in my case I was using DateTime for my Entity class. When I tried to use like

    (a.DateProperty == null ? default : a.DateProperty.Date)
    

    I had the error

    Property 'System.DateTime Date' is not defined for type 'System.Nullable`1[System.DateTime]' (Parameter 'property')
    

    So I needed to change DateTime? for my entity class and

    (a.DateProperty == null ? default : a.DateProperty.Value.Date)
    

提交回复
热议问题