The entity cannot be constructed in a LINQ to Entities query

前端 未结 14 2067
失恋的感觉
失恋的感觉 2020-11-21 06:04

There is an entity type called Product that is generated by entity framework. I have written this query

public IQueryable GetProdu         


        
14条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 06:45

    You can solve this by using Data Transfer Objects (DTO's).

    These are a bit like viewmodels where you put in the properties you need and you can map them manually in your controller or by using third-party solutions like AutoMapper.

    With DTO's you can :

    • Make data serialisable (Json)
    • Get rid of circular references
    • Reduce networktraffic by leaving properties you don't need (viewmodelwise)
    • Use objectflattening

    I've been learning this in school this year and it's a very useful tool.

提交回复
热议问题