开发者

get Generic CRUD operation in EF

开发者 https://www.devze.com 2022-12-27 04:59 出处:网络
Is there any way or design pattern can I use to get Generic CRUD operations? BecauseI’m working on n-tire applica开发者_StackOverflow社区tion using EF in the data layer and I don’t want to use CRUD

Is there any way or design pattern can I use to get Generic CRUD operations?

Because I’m working on n-tire applica开发者_StackOverflow社区tion using EF in the data layer and I don’t want to use CRUD Functions in Every Entities.

Your help would be appreciated


You can use the Repository pattern, where you implement the repository as an interface and then a base class. For instance:

IRepository where T : class
void Save(T entity )
T FindById( T id ) ....

EntityFrameworkRepositoryBase : IRepository
void Save( T entity )
{ // do EF specfic stuff }....

Then for a given entity you can create(or inject) a concrete repository:

PersonRepository : EntityFrameworkRepositoryBase

From there, simply call the PersonRepository to Save or Find Persons.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号