design - User-defined conversions to or from a base class and entity-framework -


using entity framework (ef) orm tool in 3-tier project, found entity framework generated code dal + little bll. since dal , bll different layers in scenario , different coders work on each of them, there need separating each layer different project.

the problem don't want changing ef generated code , still need project bll (i'm aware of ef partial classes , on...changing() methods doesn't make sense of separation of concepts me , partial class cannot implemented in different project).

i wish ef generate interface each entity , implement generated code. way, implement interfaces bll classes. making changes entities in ef designer lead automatically changing interfaces , bll stopped working (doesn't compile more, since interface has been changed). unfortunately ef doesn't supply interfaces , extracting them generated code hard maintain since new change model need extracting them manually again.

then thought of wrapping entity framework generated classes our own bll classes (deriving bll classes ef classes) , add bll logic there (validations, business rules...) , hide underlying methods , properties bll equivalents.

// example of new property facilitates using ef object  class efaccount // ef generated class {    datetime creationdate { get; set; }    datetime expirandate { get; set; } }  class bllaccount : efaccount // bll class {    new datetime creationdate { get; set; }    new datetime expirandate { get; set; }    // total age in days new property. storing this, in dbase cause unnecessary redundancy    int days { { return (expirationdate - creationdate).totaldays; } } } 

since bll classes derived equivalent ef classes, need casting , base class not allowed.

in case if i'm casting ef bll means object coming dbase , properties can calculated base class compiler doesn't allow casting base. , if i'm casting bll ef means object gonna stored in dbase properties throw away compiler doesn't allow casting base.

what suggest ?

the suggestion is:

  • use entity framework 4
  • use entity objects or preferably poco
  • use entity objects or poco t4 template
  • modify t4 template add additional features - generating , implementing interface based on entity properties should possible.

argument don't want codings ridiculous. have proved generated code need lot of codings , have lot of additional complications. generated doesn't mean good. not easy work generated code if can't modify generation (this possible if write own custom tool code generation). here clear advantage of t4 templates.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -