I have the following layers involved in this question:
- Service Layer (Using IoC to call Repository)
- Domain Model (POCO / Domain Entities, defined repository Interfaces)
- Repository Layer (EF .edmx and implemented repositories)
A lot of times it's really straight forward: Repository layer queries database via Entity Framework and returns IList<SomeDomainEntity> to caller which was Service Layer. The type returned is a type defined in the Domain Model.
The problem I'm running into is when I need to query across POCOs A,B, and C and get data from all to be returned. Since I don't handle any logic in the repository I need to return this data back to the Service layer to be processed (either directly or more likely by calling some logic on domain model). However I don't have a single type anymore from the results of the repository query to return to the caller.
An anonymous type of course handles this in examples I see, but since I'm not processing that logic from returned data directly in the Repository and it needs to be returned, I need a physical type to return. Here are some solutions I thought of but not sure I like any:
- Create a new domain entity in Domain Model that essentially is a composition of all the data I queried, so this new single type may be returned. This seems wrong to create abritrary types to satisy query needs.
- Make the service layer call the individual repositories on A,B,C entities separately and then deal with the data from each returned object. This seems like a lot of extra work.
- Create a ViewModel to return. This seems out of place to me as well. I leverage ViewModel classes heavily between my service layer and UI layers, but never seen them leveraged for return from the repository.
I can't be the only one querying across multiple entities to get a conglomeration of data back that needs to be add