Reputation: 377
I was practicing on WCF. I had a database and I used Entity Framework to generate entities. I have two entities called Film
and Book
. I can do list/add/delete/update on Film/Book. But I think if I have more entities, I would repeat a lot of times of the same functions (list/add/delete/update). Now what I want to do is to write a general function using C# like:
public List<"name of the entity"> GetList(the name of the entity)
{
//do something
}
I've been working on it for 2 days and I didn't make it.
Please help me!
Upvotes: 0
Views: 394
Reputation: 13531
It's called generic repository pattern: here or here, or here.
But also note this. Personally I wouldn't call it an anti-pattern, just make sure you have a repository for each aggregate root and that you can overload any of them with custom data access methods next to the generic ones.
Upvotes: 3