简体   繁体   中英

Entity Framework Projections and Return Type

I've the following project class libraries structure on my solution:

Application.Domain.Models : Entities like User, Customer. Application.DataAcess : IUserRepository, ICustomerRepository Application.Business : IUserService, ..

For one operation i need only the CustomerName and CustomerAddress then i will use entity framework projection to return only this properties.

My question is, should i create a entity for store only this properties and return it from this operation or should i return a Customer entity with only these two properties and all others with no value?

If should create a new entity, what layer it should be put in? Domain.Models, Domain.AnotherFolder or Business?

Technically you should not be constructing invalid objects. So just fetch your entire entity and use what you need. This will also mean you can reuse some existing code. You can make another entity but this should compliment your domain model. It will go in domain. If you are simply retrieving the data to use outside your domain you can consider having a lightweight readonly query layer that just passes data to whoever wants to read it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM