vb.net - Entity Framework 4 POCO Generation -
ok... have created model using ef4. great!
i turned off code generation , downloaded extension: http://visualstudiogallery.msdn.microsoft.com/23df0450-5677-4926-96cc-173d02752313 (poco entity generator). awesome!
ran it, , generates of classes. have do? seems work, repositories objects , persist db.
please have @ following code , let me know if on right track.
** sample code **
controller:
namespace controllers public class homecontroller inherits system.web.mvc.controller function index() actionresult return view(new models.homemodel) end function end class end namespace
model:
namespace models public class homemodel private _repository titan.business.repositories.icustomerrepository private _salesreprepo titan.business.repositories.isalesrepresentativerepository public property customers ienumerable(of titan.business.customer) public property salesreps ienumerable(of titan.business.salesrepresentative) public sub new() _repository = new titan.business.repositories.customerrepository _salesreprepo = new titan.business.repositories.salesrepresentativerepository _customers = _repository.query(function(x) x.lastname.startswith("str")) _salesreps = _salesreprepo.query(function(x) x.lastname.startswith("str")) end sub end class end namespace
repository , interfaces:
namespace repositories public interface irepository(of t) function query(byval predicate system.linq.expressions.expression(of func(of t, boolean))) ienumerable(of t) function getbyid(byval id integer) t sub add(byval entity t) sub delete(byval entity t) sub save(byval entity t) end interface public interface icustomerrepository inherits irepository(of customer) end interface public interface isalesrepresentativerepository inherits irepository(of salesrepresentative) end interface end namespace namespace repositories public class salesrepresentativerepository implements isalesrepresentativerepository public sub add(byval entity salesrepresentative) implements irepository(of salesrepresentative).add end sub public sub delete(byval entity salesrepresentative) implements irepository(of salesrepresentative).delete end sub public function getbyid(byval id integer) salesrepresentative implements irepository(of salesrepresentative).getbyid end function public function query(byval predicate system.linq.expressions.expression(of system.func(of salesrepresentative, boolean))) system.collections.generic.ienumerable(of salesrepresentative) implements irepository(of salesrepresentative).query using db new gtgcontainer return db.salesrepresentatives.where(predicate).tolist end using end function public sub save(byval entity salesrepresentative) implements irepository(of salesrepresentative).save end sub end class end namespace
any suggestions helpful me.
where service layer fit in?
what automapper? need use now?
dependency injection? care explain.
thanks bunch,
sam
there's great article scott allen testing entity framework 4 - creating poco classes first step, if want test business layer separate ef have introduce unit of work coordinates saving state across multiple repositories , allows di.
Comments
Post a Comment