EF6 and Onion architecture - database first and without Repository pattern

◇◆丶佛笑我妖孽 提交于 2019-12-04 18:12:39

@andree

I have a few comments that may add to this discussion. I appreciate this is an older thread but I think the discussion is still valuable.

Firstly, I would now recommend not going with EDMX files as all the future discussions for EF7 seem to indicate that EDMX will be dropped. Instead, from EF6.1 you can now generate a "code-first" style configuration from an existing database.

"Code-first" should probably be renamed to "fluent configuration"

Most Generic Repo examples tend to use leaky abstractions, because they expose methods that accept LINQ >queries (like Expression> query)

Non-generic Repos tend to cause a lot of code

I've generally found that it can be useful to be a little "leaky". We use repositories that share IQueryable so that it's easy to write quick queries - but anything that's used often get moved into the repository proper. Obviously this would make it harder to swap out the persistence layer with something else that can't give you IQueryable but in practice this has never happened to me.

My approach to the "Non-generic Repos tend to cause a lot of code" problem has been to use code generation with .tt templates. - tt templates generate a bunch of partial repository implementations and interfaces. - Then, add your own methods to this in your own partial files.

please take a look at this library:
http://www.sswdataonion.com
(disclaimer: I was one of the developers for this)
It contains tt templates to generate a repository and unit-of-work pattern.

Personally, If I was to write a truly agnostic "non-leaky" service layer I would probably just write it as a layer on top of a repository / Unit of work pattern.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!