Help me understand “LINQ to Entities only supports casting Entity Data Model primitive types”

前端 未结 1 543
你的背包
你的背包 2021-02-14 07:10

I have a unit of work and a repository using EF 4 and POCOs. Since EF requires an ordered set before it can Skip() and Take(), I added the following unit test (without mocks) j

相关标签:
1条回答
  • 2021-02-14 07:31

    It is spotting "order by {object}" and panicking; it knows how to order by string, int, short, DateTime, etc - but object is a bit too vague.

    You're going to need the actual lambda to be typed correctly; the simplest approach would be to make Get generic, i.e.

    .... Get<TIdentity>(
             Expression<Func<E, TIdentity>> orderbyLambda, int page, int pageSize)
    

    and then:

    orderbyLambda: p => p.ID
    

    should (without you changing the code at the caller) automatically make that a Get<short>(...) in this case via generic type inference. The other option is to leave it as <E,object>, but re-write the expression tree at the receiver. More work.

    0 讨论(0)
提交回复
热议问题