Can't use ternary operator to assign Linq expression

前端 未结 3 1499
轻奢々
轻奢々 2020-12-11 09:46

I just typed the following code:

Expression> expression = 
                fileTypeGroupID.HasValue ? n => n.Document.         


        
3条回答
  •  萌比男神i
    2020-12-11 10:28

    This doesn't answer you question of why the compiler could not infer the type, but an easy work around would be to write your expression this way:

    Expression> expression = 
      n => !fileTypeGroupID.HasValue || n.Document.MimeType.FileTypeGroupID == fileTypeGroupID.Value;
    

提交回复
热议问题