Page 1 of 1

Table per Concrete Type Inheritance and Associations

Posted: Wed 29 Dec 2010 11:38
by kkara
Hi,

One of the main reasons for choosing to evaluate Entity Developer is its ability to handle Table per Concrete Type Inheritance (TPC) and of course its Model First approach. I have managed to actually create a model from scratch, correctly define TPC and map it to the database! Excellent up until now.

Now, in one of my inherited classes I want to define an association. Notice that this association should be specific to the inherited class and not to the base class. The problem is that when trying to do so, Entity Developer does not allow it showing the message: "Parent class should have entity key". Obviously the designer does not recognise that the entity key belongs to the base class...

Is there a workaround for defining the association?

I should note that the version I'm using is the "Entity Developer 3.00 Standard Trial" (v. 3.0.60)...

Thanks,
Kostas

Posted: Wed 29 Dec 2010 15:03
by AndreyR
Could you please send us the model that gives you the error, or at least provide some steps to reproduce the issue?

Posted: Wed 29 Dec 2010 17:50
by kkara
I have prepared a simple model in Entity Developer, but I cannot seem to find a way to attach it to this message.

Anyway, the way to reproduce the error is to create a model with two classes implementing a Table Per Concrete Type inheritance strategy, add a third class and try to add an association between the second class (inherited) and the third one. The designer will not allow you to do that.

I workaround that has worked for me is to edit the edmx file with an XML editor and manually configure the association. Of course that beats the point of having a designer on the first place...

Posted: Thu 30 Dec 2010 09:37
by AndreyR
You can send the attachment to support * devart * com, subject "EF: Association error".

Posted: Fri 11 Feb 2011 11:45
by ruionwriting
kkara wrote:I workaround that has worked for me is to edit the edmx file with an XML editor and manually configure the association. Of course that beats the point of having a designer on the first place...
We are also evaluating the product and the purchase decision is at 90% right now.

Is there a patch to solve this?

kkara, can you provide some details about the workaround?

Posted: Tue 15 Feb 2011 13:51
by AndreyR
ruionwriting, have you tried the latest 3.20.81 build of Entity Developer for SQL Server? We have made some fixes associated with TPC handling in it.
Please let us know if the error persists.

It is ok now.

Posted: Wed 04 May 2011 14:27
by ruionwriting
UPDATE: not working 100% right now and exchanging same emails with support.
---
It was solved with one of the latest releases. Currently I'm using the lastest beta.

Solved

Posted: Tue 10 May 2011 13:55
by ruionwriting
First I would like to give thanks to the great effort for the support guys. Thank you for the step-by-step instructions:

1. Create the model via the wizard.
2. Remove the associations between Provider and *Providers (from the conceptual part only).
3. Remove the discriminator property ('Type') from the base class ('Provider').
4. Make the base class abstract.
5. Create interim classes (*ProviderBase) and derive (with the TPH inheritance) them from the base class.
6. Map interim classes to the Providers table (in the 'Mapping Details' dialog, select dbo.Providers), and add the discriminator conditions (e.g., 'Type = 1' for DomainProviderBase and 'Type = 2' for DnsProviderBase).
7. Derive (with the TPT inheritance) *Provider classes from the corresponding *ProviderBase classes.
8. Remove the key properties ('ProviderId') from the *Provider entity classes.
9. Map the ProviderId column in the *Provider classes: in the 'Mapping Details' dialog, select the ProviderId property from the drop-down list near the ProviderId column.

Posted: Wed 11 May 2011 13:10
by ruionwriting
Supplied T4 templates for POCO entities don't comply with this kind of mapping. Waiting answer from Support.

Posted: Wed 11 May 2011 15:22
by AndreyR
Could you please describe the problems you have encountered with POCO templates?
Is the code generated incorrectly?
Could you please provide some code illustrating the error in POCO templates?

Posted: Wed 11 May 2011 15:34
by ruionwriting
The generated code does not take into consideration the inheritance that we have on the model on details level, i.e, the "Type" mapping is not on the code neither on *Provider or *ProviderBase.

Posted: Thu 12 May 2011 13:39
by AndreyR
Thank you for the report. We are investigating the issue.
I will let you know about the results of our investigation.

Posted: Thu 12 May 2011 15:45
by AndreyR
If you mean EdmEntityTypeAttribute, it shouldn't be generated for POCO entities at all.
If you mean any other Type mapping, please provide more detailed information about the error.

Posted: Mon 16 May 2011 14:11
by ruionwriting
Andrey can you check with Stanislav about the procedure he sent?

Why column mapping conditions are ignored on the generated POCO? I'm following provided procedures to achieve proper mapping, now that I have everything ok with the model and the database I don't have on the classes side.

Posted: Tue 17 May 2011 12:17
by AndreyR
I have repeated the procedure and obtained a correct model. Moreover, we have performed some tests and have obtained the correct results using the following code:

Code: Select all

var q = context.Providers.OfType().ToList();
Could you please explain the behaviour you expect to get?
What attributes are missing?
Could you please provide a failing code snippet?