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

前端 未结 1 548
你的背包
你的背包 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(
             Expression> 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(...) in this case via generic type inference. The other option is to leave it as , but re-write the expression tree at the receiver. More work.

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