asp.net mvc 3 - MVC3 EF Ninject Generic Repository -
i'm working on generic repository using entity framework/mvc3/ninject.mvc3. interface looks this.
public interface irepository<tentity> tentity : class { iqueryable<tentity> query { get; } void add(tentity entity); void edit(tentity entity); void delete(tentity entity); } my concrete implementation looks this.
public class efrepository<t> : irepository<t> t : class { private efdbcontext context = new efdbcontext(); public iqueryable<t> query { { return context.set<t>().asqueryable(); } } public void add(t entity) { context.set<t>().add(entity); context.savechanges(); } public void edit(t entity) { context.entry<t>(entity).state = system.data.entitystate.modified; context.savechanges(); } public void delete(t entity) { context.set<t>().remove(entity); context.savechanges(); } } ninject has binding
kernel.bind(typeof(irepository<>)).to(typeof(efrepository<>)); what need last insert id in concrete implementation. have transaction table insert based on last table , insert id. call transaction controller, i'd rather done in data access layer, can write transaction after last insert/update.
first, above example proper way implement generic repository. second there way data want through method?
when call add on entity, , table has identity column (auto increment) can check entity after savechanges() , contain generated id.
Comments
Post a Comment