Linq “Could not translate expression… into SQL and could not treat it as a local expression.”

后端 未结 3 1388
走了就别回头了
走了就别回头了 2020-11-30 12:47

I started out with this question, which I sort of answered there, and now I\'m asking the more fundamental question here. I\'ve simplified the query down to this:



        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 13:19

    @Marc Gravell beat me to the answer, credit also to the various answerers to this question who put me on the right track.

    I did it much like Marc's first suggestion, like so:

    var q1 = from ent in LinqUtils.GetTable()
             from tel in ent.Telephones.DefaultIfEmpty()
             select new { ent, tel };
    var q2 = from q in q1.AsEnumerable()
             select new {
               Name = q.ent.FormattedName,
               Tel = q.tel != null ? q.tel.FormattedNumber : ""
             };
    

    And that did it! Thanks, all!

提交回复
热议问题