c# - Entity Framework in n-Tier -
using simple example:
- presentation tier : aspx , code behind.
- business tier: wcf related logics
- data access tier: wcf entity framework
when want populate grid view, there need call method form business logic, in turns call data access tier's method.
the methods , related logic follow.
data access tier:
public sampleentity[] loadsampleentity() { //retrieve sampleentity database. }
business logic tier:
public sampleentity[] getsampleentity() { //call proxy access data access tier //call loadsampleentity() }
presentation tier:
protected void btn_onclick() { //call proxy access business logic tier //call getsampleentity() //sampleentity[] sampleentity=businesslogic.getsampleentity(); //gridview.datasouce = sampleentity //gridview.databind(); }
given structure, if sampleentity modified, 3 tiers require re-compiling.
there way reduce need of re-compiling when new property/column added sampleentity .
one way have worked on convert sampleentity[] datatable type @ business logic tier, , pass datatable on presentation tier. doing removes intellisense feature of entityframework in presentation tier.
you try repository pattern. you'd first have domain layer of objects similar entity objects, domain layer in it's own project/dll. use automapper map values entity object on domain object, via business layer. presentation layer would/could share domain object layer, way abstract entity data layer behind
irepository<t> { ienumerable<t> getall(); t getbyid(int id); void save(t savethis); void delete(t deletethis); }
your type t each table domain type , inside these methods you'd map entity type domain type. irepository can service contract on data tier access.
as other question change make entity object need reflected in domain object can done automapper. think in cases don't want share ef or linqtosql data type way out view or ui.
since it's wcf have domain layer serialized types.
Comments
Post a Comment