WHAT I HAVE:
Visual Basic 2010, .NET Framework 4.0, Entity Framework 4.0, SQL Express
QUESTION 1 : Accessing derived types
Suppose one has an entity called SocialContact, which is inherited by Person, and Person is in turn is inherited by PersonalFriend. (Personal Friend < Person < SocialContact) In order to access the derived entities, one has to use LINQ and the .OfType(Of derivedtype) property on Entity. For instance,
' get list of SocialContacts and individual SocialContact Dim SocialContacts As List(Of SocialContact) = _ (From sc In objectContext.SocialContacts _ Select sc).ToList Dim SocialContact As SocialContact = SocialContacts.First ' get list of People & individual Person Dim People As List(Of Person) = _ (From p In objectContext.SocialContacts.OfType(Of Person) _ Select p).ToList Dim Person As Person = People.First ' get list of PersonalFriends & individual PersonalFriend Dim PersonalFriends As List(Of PersonalFriend) = _ (From p In objectContext.SocialContacts.OfType(Of PersonalFriend) _ Select p).ToList Dim PersonalFriend As PersonalFriend = PersonalFriends.First
What's the question? Well--I have converted the code on page, "How to have a property on ObjectContext which returns the derived entities?" (http://msmvps.com/blogs/matthieu/archive/2008/08/21/how-to-have-a-property-on-objectcontext-which-returns-the-derived-entities.aspx?CommentPosted=true#commentmessage), from C# to Visual Basic and saved it to a file. I need to know a few things about this SampleEdmxCodeGenerator class and the SampleEdmxCodeGen project that it comes from:
a. Will this work on my version of VS/.NET/Entity Framework?
b. Where do I place this code in VS 2010/my project and how do I run it?
c. Will it work for all derived entities of all base entities in ANY project? Does it eliminate the need for the .TypeOf() stuff to get at the derived entities?
d. If I associate an entity, say X, with an entity Y, and entity Y1a is derived (directly or indirected) from Y, how will the project and code view and handle the relationship between X and Y1a? (see "QUESTION 2")
e. Is there anything else I should know (I'm not an expert at code-generation tools)?
QUESTION 2: Derived entities and associations with their base entities
If I associate a base entity (i.e., SocialContact) with another (non-derived) entity, say, Address, how are the derived entities related to it, from a VB-code standpoint? That is, what's the relationship between Person & Address, PersonalFriend & Address, etc.? (Are they the same as SocialContact & Address?) Are there any special considerations I have to make, say, when cross-referencing PersonalFriend and Adress in my code (vs. SocialContact & Address)--say, when doing "join" queries and stuff?
QUESTION 3: Table-per-Heirarchy and Model-first
I'm using the model-first approach to my project. Can I do table-per-heirarchy inheritance under these conditions? (I know I can do table-per-type.)
- Edited by RobertGustafson Saturday, October 19, 2013 2:14 PM
>>QUESTION 3: Table-per-Heirarchy and Model-first
The Blog will be helpful to you, I think.
- Proposed as answer by Fred Bao - MSFTMicrosoft contingent staff, Moderator Tuesday, October 22, 2013 2:50 AM
- Marked as answer by Fred Bao - MSFTMicrosoft contingent staff, Moderator Thursday, October 31, 2013 9:32 AM