Print Page | Close Window

Code First Base Class

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=3590
Printed Date: 13-May-2026 at 2:59am


Topic: Code First Base Class
Posted By: Vonzkie
Subject: Code First Base Class
Date Posted: 22-Aug-2012 at 1:16am
Hi

I created a base class for all my Code First Entities and I put the base class in a separate project or assembly.
Now, using Code Second Approach, I enter the inject base class like 'OtherProject.EntityBase' and it generates all the codes and I was able to compile the whole project.
When I try to execute the query like:

var context = new DomainEntities(some parameters here);
var result = context.Sample.ToList();

This error will show:

Unable to get metadata for  OtherProject.EntityBase . Make sure it is a valid entity type or POCO type with a KeyAttribute

Am I missing something?

Do i need to have a metadata (ibmmx) or something before it work?

Thanks,
Von



Replies:
Posted By: sbelini
Date Posted: 23-Aug-2012 at 1:29pm
Von,
 
I was not able to reproduce it here.
I'm sending the CodeFirstWalk sample modified so the base class is in a different assembly.
uploads/892/CodeFirstWalk_BaseClass_in_separate_assembly.zip - uploads/892/CodeFirstWalk_BaseClass_in_separate_assembly.zip
 
Regards,
   Silvio.


Posted By: Vonzkie
Date Posted: 23-Aug-2012 at 4:25pm
Hi Silvio,

I'm not sure if this is related but I don't have a custom DBContext, I only use EntityManager and I'm in an n-Tier environment so I have a BOS here.

Thanks,
Von


Posted By: sbelini
Date Posted: 23-Aug-2012 at 4:55pm
Von,
 
A Code First model without a DbContext worked as well. (see sample: uploads/892/Silverlight_CodeFirstTourOfDevForce_BaseClassInDifferentAssembly.zip - uploads/892/Silverlight_CodeFirstTourOfDevForce_BaseClassInDifferentAssembly.zip )
 
When you have the base class in the same assembly, does it work?
When you build, is the .ibmmx file generated?
 
Note that Code Second might not produce a 100% working code and you might have to make little changes to it.
 
Silvio.


Posted By: Vonzkie
Date Posted: 23-Aug-2012 at 5:02pm
When you have the base class in the same assembly, does it work?
- Yes it worked
- The weird thing here is that, I just transferred the base class to a different assembly and now it doesn't work.

When you build, is the .ibmmx file generated?
- Yes, in the Model project not in the BaseClass project




Posted By: sbelini
Date Posted: 23-Aug-2012 at 10:38pm
Von,
 
Please provide a reproducible test case.
 
Silvio.


Posted By: Vonzkie
Date Posted: 27-Aug-2012 at 11:13pm
Hi Silvio,

I found the culprit. :)
I forgot to include the Base Class Assembly into my Search Composition List. 

Thanks,
Von



Print Page | Close Window