asp.net mvc - EF model first with MVC Repository Pattern -
attempting create mvc project using ef , model first approach.
in order implement in way web , info portions loosely coupled i'm attempting implement repository pattern, but, after reading many articles i'm still trying grasp objects repository interface should homecoming or how should bind/map 'm' model in mvc project.
here's simplistic illustration of i'm asking.
//repository interface public interface imemberrepository { fellow member getbyid(int id); ienumerable<member> findbyname(string name); } //repository interface implementation public class memberrepository : imemberrepository { //my db context object created ef private mycontainer context; public memberrepository(mycontainer context) { this.context = context; } public fellow member getbyid(int id) { homecoming context.members.singleordefault(x => x.id == id); } public ienumerable<member> findbyname(string name) { homecoming context.members.find(x => x.name == name); } }
so using ninject di framework phone call controller follows:
public class groupscontroller : controller { public viewresult find(string name) { imemberrepository repo = objectfactory.instance.createinstance<imemberrepository>(); homecoming repo.findbyname(name); } }
at point i'm not understanding how fellow member object (from ef model) supposed bind/map 'mvc' fellow member model object. seems must missing sort of mapping layer or i'm off track. if reference ef generated class straight feels i'm negating point of using interface , di framework. advice or direction @ point appreciated.
your imemberrepository
interface , implementation memberrepository
right me. how construction database code well.
moving mvc world, create view models populate info model. give flexibility of adding attributes or additional properties need in view.
this workflow:
fetch object(s) repository populate view model objects info repository object(s) return view model view controller asp.net-mvc entity-framework repository-pattern ef-model-first
No comments:
Post a Comment