Table per hierarchy inheritance with POCO entities in Entity Framework 4 -


Our organization is looking for standardization on Entity Framework once v4 comes out. As a result, I see that our What will it take to migrate the application, which uses NHibernate firmly for EF4 using POCO support. In some places we use single table succession (which is also called table per hierarchy) I have been unable to work to use it.

Payment (base class (should be abstract, but there should be trouble too)) Credit Card Payment (Solid Implementation) AHP Payment (Solid Implementation) Check Payment (Solid Implementation)

Right now, I'm mapping them with only base class properties. All of these classes are in the same namespace. They have a discriminant, which is called the payday's ID in the database, so in the payment mapping, when the status of "When the paymentTapID = 0" occurs. There is only one position with different values ​​(i.e. credit card payment = 1, etc.) in each subclass.

When I Data Context Using payments, I try to load a list of all the payments. TOList () (DataContext inherits from ObjectContext) I get the following exception:

"Data mapping was not found for type with identity mapping 'DataLayer.DataModel.CreditCardPayment'."

I do not understand what this means, because the POCO credit card payment class resides in the same namespace as the POCO payment class (actually in the same file).

What am I missing?

This is not complaining about database mapping, but the CLR mapping model.

EF can not do it for any reason to find your credit card payment category.

Now one possible reason is that you have not yet loaded the metadata for this.

For example if you have this:

  Assembly 1: - Payment Assembly 2 reference assembly 1: - Credit card payment payment increases  

Then you do not know where EF remains, where the credit card payment remains.

The way to move around this is LoadAssembly:

 using  (DataContext ctx = new DataContext ()) {ctx.MetadataWorkspace .LoadFromAssembly (typeof (CreditCardPayment) .Assembly); // Now do your query}  

You need to tell LoadFromAssembly to each assembly that is not directly reference to your DataContext class is.

Note: typeof (payment). Assembly << code> directly IQueryable & lt; Payment & gt; is due to the property of the payment.

Hope this helps


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -