开发者

get Generic CRUD operation in EF

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜