Table per Concrete Type Inheritance and Associations

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
kkara
Posts: 7
Joined: Mon 27 Dec 2010 10:24

Table per Concrete Type Inheritance and Associations

Post by kkara » Wed 29 Dec 2010 11:38

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 29 Dec 2010 15:03

Could you please send us the model that gives you the error, or at least provide some steps to reproduce the issue?

kkara
Posts: 7
Joined: Mon 27 Dec 2010 10:24

Post by kkara » Wed 29 Dec 2010 17:50

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...

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 30 Dec 2010 09:37

You can send the attachment to support * devart * com, subject "EF: Association error".

ruionwriting
Posts: 10
Joined: Fri 11 Feb 2011 11:35
Location: PT

Post by ruionwriting » Fri 11 Feb 2011 11:45

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?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 15 Feb 2011 13:51

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.

ruionwriting
Posts: 10
Joined: Fri 11 Feb 2011 11:35
Location: PT

It is ok now.

Post by ruionwriting » Wed 04 May 2011 14:27

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.

ruionwriting
Posts: 10
Joined: Fri 11 Feb 2011 11:35
Location: PT

Solved

Post by ruionwriting » Tue 10 May 2011 13:55

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.

ruionwriting
Posts: 10
Joined: Fri 11 Feb 2011 11:35
Location: PT

Post by ruionwriting » Wed 11 May 2011 13:10

Supplied T4 templates for POCO entities don't comply with this kind of mapping. Waiting answer from Support.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 11 May 2011 15:22

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?

ruionwriting
Posts: 10
Joined: Fri 11 Feb 2011 11:35
Location: PT

Post by ruionwriting » Wed 11 May 2011 15:34

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 12 May 2011 13:39

Thank you for the report. We are investigating the issue.
I will let you know about the results of our investigation.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 12 May 2011 15:45

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.

ruionwriting
Posts: 10
Joined: Fri 11 Feb 2011 11:35
Location: PT

Post by ruionwriting » Mon 16 May 2011 14:11

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 17 May 2011 12:17

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?

Post Reply