Thursday, 15 May 2014

c# - What type to return when querying multiple entities in Repository layer? -



c# - What type to return when querying multiple entities in Repository layer? -

i have next layers involved in question:

service layer (using ioc phone call repository) domain model (poco / domain entities, defined repository interfaces) repository layer (ef .edmx , implemented repositories)

a lot of times it's straight forward: repository layer queries database via entity framework , returns ilist<somedomainentity> caller service layer. type returned type defined in domain model.

the problem i'm running when need query across pocos a,b, , c , info returned. since don't handle logic in repository need homecoming info service layer processed (either straight or more calling logic on domain model). don't have single type anymore results of repository query homecoming caller.

an anonymous type of course of study handles in examples see, since i'm not processing logic returned info straight in repository , needs returned, need physical type return. here solutions thought of not sure any:

create new domain entity in domain model composition of info queried, new single type may returned. seems wrong create abritrary types satisy query needs. make service layer phone call individual repositories on a,b,c entities separately , deal info each returned object. seems lot of work. create viewmodel return. seems out of place me well. leverage viewmodel classes heavily between service layer , ui layers, never seen them leveraged homecoming repository.

i can't 1 querying across multiple entities conglomeration of info needs added type , returned caller. mutual practice or standard way of going solve problem?

thanks!

if entities related , query of them in 1 place should seek find aggregate root of them in domain model or if doesn't exist yet should introduce new one, said in first option. not wrong until makes sense. should model domain concept , have 1 because created repository method.

if entities not related (well, related in way, not tightly above) , want them in 1 go should handle in service layer can utilize multiple repositories , compose result object.

you heard of concept of navigation properties , eager loading write here because may reply question (i don't see domain model)

i wouldn't go 3rd suggestion (create viewmodels in repository) because breaks separations.

c# entity-framework repository-pattern

No comments:

Post a Comment