jeudi 9 avril 2015

How to resolve generic repository and use it in a single variable for different tables?

I'm trying to built some generic code for tables with the same columns but i have a problem figuring out how to use a generic "resolver" in order to use only one variable.


I tried to use dynamic without success and i'm out of ideas.


Entity1, Entity2 and Entity3 have exactly the same fields but there are different tables. Is possible to use only one variable to get the results?



var repository1 = new RepositoryBase<Entity1>();
var repository2 = new RepositoryBase<Entity2>();
var repository3 = new RepositoryBase<Entity3>();

Enum RepositoryTypes
{
Repo1 = 0,
Repo2 = 1,
Repo3 = 2
}

var repository = RepositoryResolver(RepositoryTypes repoTypes);

var results = repository.Get(record => record.Name.Contains("fist name")).ToList();

foreach(var person in results)
{
Console.WriteLine("First Name: {0}, Last Name: {1}", person.Name, person.LastName);
}


Thanks!






Aucun commentaire:

Enregistrer un commentaire