New Posts New Posts RSS Feed: Customer specific model changes (code first)
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Customer specific model changes (code first)

 Post Reply Post Reply
Author
Thomas View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Feb-2012
Posts: 23
Post Options Post Options   Quote Thomas Quote  Post ReplyReply Direct Link To This Post Topic: Customer specific model changes (code first)
    Posted: 16-May-2012 at 3:47am
I am currently working on a structure for a base project which I would like to extend from for the customers.

That means if there are no changes I would have something like a core model project and a customer model project which just has empty classes that extend the base model classes, but if there is a change that is only relevant for the customer I would just do a change for the customer model project.

Would this work with DevForce (EF) code first?



Edited by Thomas - 16-May-2012 at 3:48am
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 17-May-2012 at 4:43pm
Hi Thomas,
 
After doing some experimenting I found that unfortunately this is not possible.
 
The issue I came accross is that it can't find the BaseEntity type in the custom assembly.
 
A possible solution would be using partial classes. Howeve, in this case all code should be in the same assembly.
 
Regards,
   Silvio.
Back to Top
Thomas View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Feb-2012
Posts: 23
Post Options Post Options   Quote Thomas Quote  Post ReplyReply Direct Link To This Post Posted: 17-May-2012 at 11:47pm
This was also the only "solution" that I got to work. The problem is that by using this method I don't really know how to manage multiple customers properly. 
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 18-May-2012 at 10:49am
You could have a partial class for each customer that needs specific changes and then use conditional compilation symbols

Entity_Customer1.cs
#if CUSTOMER1
properties here
#endif

Entity_Customer2.cs
#if CUSTOMER2
properties here
#endif

Not the cleanest but I'm not sure how else you will achieve it
Back to Top
Thomas View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Feb-2012
Posts: 23
Post Options Post Options   Quote Thomas Quote  Post ReplyReply Direct Link To This Post Posted: 19-May-2012 at 4:31am
Just if anyone else is interessted. In EF you can solve the problem by using the following in the DBContext (constructor):

(this as IObjectContextAdapter).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(<entity from other assembly>).Assembly);

The only problem is that this is currently not supported by DevForce, but according to sbelini it is logged as a feature request.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 19-May-2012 at 2:08pm
Very cool, thanks for sharing
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down