Answered by:
EF 4.0 "Generate Database From Model"

Question
-
Hallo,
I have a Model with 2 inherited Entities (Product, ConcreteProduct). I generate a SQL DDL using "Generate Database From Model" (SQL Compact Server 3.5 SP1).
If I'll add a new "ADO.NET Entity Data Model" using the generated Database I get an Association and no Inheritance.
My Question is now, what is the "best" table design solution for inheritence in EF Framework?
Here the generated Code VS 2010:
....
ALTER TABLE [ConcreteProducts]
ADD CONSTRAINT [FK_ConcreteProduct_inherits_Product]
FOREIGN KEY ([ID])
REFERENCES [Products]
([ID])
ON DELETE NO ACTION ON UPDATE NO ACTION;
GO...
thx
Martin
Thursday, April 29, 2010 2:06 PM
Answers
-
Hi,
The "Generate Database From Model" uses a Table Per Type strategy (There are other inheritence strategies like Table Per Hierarchy and Table Per Concrete Type).
Since you tried to generate a model from the created database you get a naked model.
In order to use inheritence you will have to customize the model with Table Per Type strategy again (It isn't being done by EF for you).
I hope it will help you.
Gil Fink- Proposed as answer by Jonathan Aneja -- MSFT Tuesday, May 4, 2010 3:05 AM
- Marked as answer by Michael Sun [MSFT]Microsoft employee Friday, May 14, 2010 1:05 AM
Thursday, April 29, 2010 3:40 PM -
Hello Martin,
Welcome to ADO.NET Entity Framework and LINQ to Entities forum!
How is the problem now? I think Gil’s post is very helpful and informative for the question. The default inheritance strategy for EF4 is the TPT inheritance. For more about the how to use Model First and its “under the hood” information, please see
http://blogs.msdn.com/efdesign/archive/2008/09/10/model-first.aspx
http://blogs.msdn.com/adonet/archive/2009/11/05/model-first-with-the-entity-framework-4.aspx
Have a nice weekend, both!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked as answer by Michael Sun [MSFT]Microsoft employee Friday, May 14, 2010 1:05 AM
Saturday, May 1, 2010 4:31 PM
All replies
-
Hi,
The "Generate Database From Model" uses a Table Per Type strategy (There are other inheritence strategies like Table Per Hierarchy and Table Per Concrete Type).
Since you tried to generate a model from the created database you get a naked model.
In order to use inheritence you will have to customize the model with Table Per Type strategy again (It isn't being done by EF for you).
I hope it will help you.
Gil Fink- Proposed as answer by Jonathan Aneja -- MSFT Tuesday, May 4, 2010 3:05 AM
- Marked as answer by Michael Sun [MSFT]Microsoft employee Friday, May 14, 2010 1:05 AM
Thursday, April 29, 2010 3:40 PM -
Hello Martin,
Welcome to ADO.NET Entity Framework and LINQ to Entities forum!
How is the problem now? I think Gil’s post is very helpful and informative for the question. The default inheritance strategy for EF4 is the TPT inheritance. For more about the how to use Model First and its “under the hood” information, please see
http://blogs.msdn.com/efdesign/archive/2008/09/10/model-first.aspx
http://blogs.msdn.com/adonet/archive/2009/11/05/model-first-with-the-entity-framework-4.aspx
Have a nice weekend, both!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked as answer by Michael Sun [MSFT]Microsoft employee Friday, May 14, 2010 1:05 AM
Saturday, May 1, 2010 4:31 PM -
Hello Linzhi
Thanks Visual Studio 2010 works great. But I had probelms with the "impendance".
If you will work on both sides (SQL Server and entity model) at the same time you will get problems.
As an OO developer I prefer working with the entity model.
Best regards
Martin Lang
Tuesday, May 4, 2010 11:15 AM -
Hi Martin,
What’s the “impendance” issue you encounter now? Model First lets us work on the entity model and it is really a fantastic feature I can imagine.
Have a nice day!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.Wednesday, May 5, 2010 9:05 AM -
Hi Martin,
How is the problem now? If you need any further assistance, please feel free to let me know.
Have a great day!
Best Regards,
Lingzhi Sun
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.Wednesday, May 12, 2010 1:07 AM