Print Page | Close Window

Customer specific model changes (code first)

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3441
Printed Date: 23-May-2025 at 3:22pm


Topic: Customer specific model changes (code first)
Posted By: Thomas
Subject: Customer specific model changes (code first)
Date 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?




Replies:
Posted By: sbelini
Date 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.


Posted By: Thomas
Date 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. 


Posted By: smi-mark
Date 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


Posted By: Thomas
Date 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.


Posted By: smi-mark
Date Posted: 19-May-2012 at 2:08pm
Very cool, thanks for sharing



Print Page | Close Window