c# - Implement searching in a generic repository with Linq Expressions -


i working entity framework , code first. here simple example show case.

public class personefmodel {     public int id { get; set; }     public string vorname { get; set; }     public string nachname { get; set; } }  public class efcontext : dbcontext {     public dbset<person> personen { get; set; } } 

to independent implementation of data access wrote abstraction layer repositories.

public class person {     public int id { get; set; }     public string vorname { get; set; }     public string nachname { get; set; } }  public interface igenericrepository<t> {     int count { get; }      void add(t item);     void delete(t item);     void update(t item);      t getdata(int id);     ienumerable<t> getdata();     ienumerable<t> getdata(int offset, int count);      ienumerable<t> find(expression<func<t,bool>> predicate);     ienumerable<t> find(ienumerable<expression<func<t, bool>>> predicates); } 

person , personefmodel has 2 different types in order independent database models. there generic repository of type person dont know how implement find methods. can execute expressions against database depends on personefmodel , not on person.

so there way translate expression<func<person, bool>> expression<func<personefmodel, bool>> execute against database or on wrong path?

if following domain-driven design don't need create 2 separate objects represent person. person class poco , represents exact entity need in own code (you using code first after-all).

you introducing , unnecessary complexity. every time change person class need change personefmodel class , repository working need use kind of mapper (automapper) , map person personefmodel unnecessary 2 identical.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -