locked
Associations RRS feed

  • Question

  • Hi

    I used Two Tables from the adventure work Db Employees , Contact

    to make an EDM Model

     

    and try to access it using the object service layer like this

     

    Code Snippet

    Dim a As New AdventureWorksEntities

    Dim employee = a.CreateQuery(Of Employee)("SELECT VALUE p FROM AdventureWorksConnection.employee AS p")

    For Each p In employee

    ListBox1.Items.Add(p.EmployeeID.ToString)

    Next

     

    But i cant access the properties in the contact entity that belong to specific employee

    Based in the relation associated in csdl file

     

    how can i do that

    Monday, June 18, 2007 1:18 PM

Answers

  • Okay; here are the sample mappings.

     

    One way to map this would be as inheritance; Employees derive from Contacts.  This is how the Adventureworks schema is laid out, and is useful if you intend on including other entity types that derive from Contacts in your model (for example, a Customer, a VendorContact, etc...).

     

    The second way to map this would be through "EntitySplitting", by mapping the Employee entity to columns in both Employees and Contacts tables.  This method would be useful if you model was just dealing with Employees as employees, and not interested in other types of contacts.

     

    Both sets of mappings are shown below, using Orcas Beta 1:

     

    SSDL

    In order for Employee to derive from Contact, or to map Employee to both Contact and Employee tables, Contact and Employee must share the same key.  Below I've made ContactID the  Key for both the Contact type and the Employee type.

    Storage Schema Definition (SSDL)

     

    <?xml version="1.0" encoding="utf-8"?>

    <Schema Namespace="AdventureWorks" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">

      <EntityContainer Name="HumanResources">

        <EntitySet Name="Employee" EntityType="AdventureWorks.Employee" />

        <EntitySet Name="Contact" EntityType="AdventureWorks.Contact" Schema="Person" />

      </EntityContainer>

      <EntityType Name="Employee" Key="ContactID">

        <Property Name="EmployeeID" Type="int" Nullable="false" StoreGeneratedPattern="identity" />

        <Property Name="NationalIDNumber" Type="nvarchar" Nullable="false" MaxLength="15" />

        <Property Name="ContactID" Type="int" Nullable="false" />

        <Property Name="LoginID" Type="nvarchar" Nullable="false" MaxLength="256" />

        <Property Name="ManagerID" Type="int" />

        <Property Name="Title" Type="nvarchar" Nullable="false" MaxLength="50" />

        <Property Name="BirthDate" Type="datetime" Nullable="false" />

        <Property Name="MaritalStatus" Type="nchar" Nullable="false" MaxLength="1" />

        <Property Name="Gender" Type="nchar" Nullable="false" MaxLength="1" />

        <Property Name="HireDate" Type="datetime" Nullable="false" />

        <Property Name="SalariedFlag" Type="bit" Nullable="false" />

        <Property Name="VacationHours" Type="smallint" Nullable="false" />

        <Property Name="SickLeaveHours" Type="smallint" Nullable="false" />

        <Property Name="CurrentFlag" Type="bit" Nullable="false" />

        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />

        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />

      </EntityType>

      <EntityType Name="Contact" Key="ContactID">

        <Property Name="ContactID" Type="int" Nullable="false" StoreGeneratedPattern="identity" />

        <Property Name="NameStyle" Type="bit" Nullable="false" />

        <Property Name="Title" Type="nvarchar" MaxLength="8" />

        <Property Name="FirstName" Type="nvarchar" Nullable="false" MaxLength="50" />

        <Property Name="MiddleName" Type="nvarchar" MaxLength="50" />

        <Property Name="LastName" Type="nvarchar" Nullable="false" MaxLength="50" />

        <Property Name="Suffix" Type="nvarchar" MaxLength="10" />

        <Property Name="EmailAddress" Type="nvarchar" MaxLength="50" />

        <Property Name="EmailPromotion" Type="int" Nullable="false" />

        <Property Name="Phone" Type="nvarchar" MaxLength="25" />

        <Property Name="PasswordHash" Type="varchar" Nullable="false" MaxLength="128" />

        <Property Name="PasswordSalt" Type="varchar" Nullable="false" MaxLength="10" />

        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />

        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />

      </EntityType>

    </Schema> 

     

    Inheritance Conceptual Model (CSDL):

    The following XML describes the conceptual model where Employee derives from Contact (note the use of BaseType in the definition of the Employee EntityType.

    Inheritance Conceptual Schema Definition (CSDL)

     

    <?xml version="1.0" encoding="utf-8"?>

    <Schema Namespace="AdventureWorksModel_Inheritance" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">

      <EntityContainer Name="AdventureWorksEntities">

        <EntitySet Name="Contacts" EntityType="AdventureWorksModel_Inheritance.Contact" />

      </EntityContainer>

      <EntityType Name="Contact" Key="ContactID">     

        <Property Name="ContactID" Type="Int32" Nullable="false" />

        <Property Name="NameStyle" Type="Boolean" Nullable="false" />

        <Property Name="Title" Type="String" MaxLength="8" />

        <Property Name="FirstName" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="MiddleName" Type="String" MaxLength="50" />

        <Property Name="LastName" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="Suffix" Type="String" MaxLength="10" />

        <Property Name="EmailAddress" Type="String" MaxLength="50" />

        <Property Name="EmailPromotion" Type="Int32" Nullable="false" />

        <Property Name="Phone" Type="String" MaxLength="25" />

        <Property Name="PasswordHash" Type="String" Nullable="false" MaxLength="128" Unicode="false" />

        <Property Name="PasswordSalt" Type="String" Nullable="false" MaxLength="10" Unicode="false" />

        <Property Name="rowguid" Type="Guid" Nullable="false" />

        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />

      </EntityType>

      <EntityType Name="Employee" BaseType="Self.Contact">

        <Property Name="EmployeeID" Type="Int32" Nullable="false" />

        <Property Name="NationalIDNumber" Type="String" Nullable="false" MaxLength="15" />

        <Property Name="LoginID" Type="String" Nullable="false" MaxLength="256" />

        <Property Name="EmployeeTitle" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="BirthDate" Type="DateTime" Nullable="false" />

        <Property Name="MaritalStatus" Type="String" Nullable="false" MaxLength="1" FixedLength="true" />

        <Property Name="Gender" Type="String" Nullable="false" MaxLength="1" FixedLength="true" />

        <Property Name="HireDate" Type="DateTime" Nullable="false" />

        <Property Name="SalariedFlag" Type="Boolean" Nullable="false" />

        <Property Name="VacationHours" Type="Int16" Nullable="false" />

        <Property Name="SickLeaveHours" Type="Int16" Nullable="false" />

        <Property Name="CurrentFlag" Type="Boolean" Nullable="false" />

        <Property Name="Employee_rowguid" Type="Guid" Nullable="false" />

        <Property Name="Employee_ModifiedDate" Type="DateTime" Nullable="false" />

      </EntityType>

     </Schema>

     

    Inheritance Mapping (MSL):

    The mapping file for inheritance shows both Employee and Contact mapped to the same EntitySet (Contacts).  Note that the TypeName for the Contact EntityTypeMapping is "IsTypeOf(Contact)", meaning that this is the mapping for the base type Contact.

    Inheritance Mapping Definition (MSL)

     

    <?xml version="1.0" encoding="utf-8"?>

    <Mapping xmlns:cs="urn:schemas-microsoft-com:windows:storage:mapping:CS" cs:Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">

    <cs:EntityContainerMapping cs:StorageEntityContainer="HumanResources" cs:CdmEntityContainer="AdventureWorksEntities">

     <cs:EntitySetMapping cs:Name="Contacts" >

      <cs:EntityTypeMapping cs:TypeName="IsTypeOf(AdventureWorksModel_Inheritance.Contact)">

        <cs:TableMappingFragment cs:TableName="Contact">         

          <cs:ScalarProperty cs:Name="ContactID" cs:ColumnName="ContactID" />

          <cs:ScalarProperty cs:Name="NameStyle" cs:ColumnName="NameStyle" />

          <cs:ScalarProperty cs:Name="Title" cs:ColumnName="Title" />

          <cs:ScalarProperty cs:Name="FirstName" cs:ColumnName="FirstName" />

          <cs:ScalarProperty cs:Name="MiddleName" cs:ColumnName="MiddleName" />

          <cs:ScalarProperty cs:Name="LastName" cs:ColumnName="LastName" />

          <cs:ScalarProperty cs:Name="Suffix" cs:ColumnName="Suffix" />

          <cs:ScalarProperty cs:Name="EmailAddress" cs:ColumnName="EmailAddress" />

          <cs:ScalarProperty cs:Name="EmailPromotion" cs:ColumnName="EmailPromotion" />

          <cs:ScalarProperty cs:Name="Phone" cs:ColumnName="Phone" />

          <cs:ScalarProperty cs:Name="PasswordHash" cs:ColumnName="PasswordHash" />

          <cs:ScalarProperty cs:Name="PasswordSalt" cs:ColumnName="PasswordSalt" />

          <cs:ScalarProperty cs:Name="rowguid" cs:ColumnName="rowguid" />

          <cs:ScalarProperty cs:Name="ModifiedDate" cs:ColumnName="ModifiedDate" />

        </cs:TableMappingFragment>

      </cs:EntityTypeMapping>

      <cs:EntityTypeMapping cs:TypeName="AdventureWorksModel_Inheritance.Employee">

        <cs:TableMappingFragment cs:TableName="Employee">

          <cs:ScalarProperty cs:Name="ContactID" cs:ColumnName="ContactID" />

          <cs:ScalarProperty cs:Name="EmployeeID" cs:ColumnName="EmployeeID" />

          <cs:ScalarProperty cs:Name="NationalIDNumber" cs:ColumnName="NationalIDNumber" />

          <cs:ScalarProperty cs:Name="LoginID" cs:ColumnName="LoginID" />

          <cs:ScalarProperty cs:Name="EmployeeTitle" cs:ColumnName="Title" />

          <cs:ScalarProperty cs:Name="BirthDate" cs:ColumnName="BirthDate" />

          <cs:ScalarProperty cs:Name="MaritalStatus" cs:ColumnName="MaritalStatus" />

          <cs:ScalarProperty cs:Name="Gender" cs:ColumnName="Gender" />

          <cs:ScalarProperty cs:Name="HireDate" cs:ColumnName="HireDate" />

          <cs:ScalarProperty cs:Name="SalariedFlag" cs:ColumnName="SalariedFlag" />

          <cs:ScalarProperty cs:Name="VacationHours" cs:ColumnName="VacationHours" />

          <cs:ScalarProperty cs:Name="SickLeaveHours" cs:ColumnName="SickLeaveHours" />

          <cs:ScalarProperty cs:Name="CurrentFlag" cs:ColumnName="CurrentFlag" />

          <cs:ScalarProperty cs:Name="Employee_rowguid" cs:ColumnName="rowguid" />

          <cs:ScalarProperty cs:Name="Employee_ModifiedDate" cs:ColumnName="ModifiedDate" />

        </cs:TableMappingFragment>

      </cs:EntityTypeMapping>

     </cs:EntitySetMapping>

    </cs:EntityContainerMapping> 

    </Mapping>

     

     Inheritance Example: 

    The following code shows querying only for those contacts that are employees, and accessing both contact and employee properties on the result.  Because a query against the Contacts table could return a any contact (whether it is an employee or not), we use the Is Of (type) operator to limit the results to employees, and the Treat() operator to return the results as employees, rather than just Contacts. 

    Inheritance Example

     

        Sub DoInheritance()

            Dim a As New AdventureWorksEntities( _

              "name=AdventureWorksEntities_Inheritance")

            Dim employee = a.CreateQuery(Of Employee)( _

              "SELECT VALUE treat(p as AdventureWorksModel_Inheritance.Employee) " & _

    FROM contacts AS p " & _

              "WHERE p Is Of (AdventureWorksModel_Inheritance.Employee)")

            For Each p In employee

                Console.WriteLine("{0} {1} {2}", _

    p.EmployeeID, p.FirstName, p.LastName)

            Next

            Console.ReadLine()

        End Sub

     

    This mapping would be useful if you wanted to sometimes query for Contacts that weren’t employees. Alternatively, if you were only interested in Employees, there would be no reason to include Contacts as the base entity type in your mapping, and you could simply map the Employee entity type to both Employee and Contacts tables, as shown in the following example.

     

    EntitySplitting SSDL:

    In the case of EntitySplitting (mapping Employee to both Employee and Customer tables) I can use the same ssdl as in the previous example.

     

    EntitySplitting Conceptual Model (CSDL):

    The following XML describes a conceptual schema with a simple Employee type that maps to an Employees table with no inheritance.  Note that, again, ContactID is used as the key since it is a common key across contacts and employees.

    Entity Splitting Conceptual Model (CSDL)

     

    <?xml version="1.0" encoding="utf-8"?>

    <Schema Namespace="AdventureWorksModel_Splitting" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">

      <EntityContainer Name="AdventureWorksEntities">

        <EntitySet Name="Employees" EntityType="AdventureWorksModel_Splitting.Employee" />

      </EntityContainer>

      <EntityType Name="Employee" Key="ContactID">

        <Property Name="ContactID" Type="Int32" Nullable="false" />

        <Property Name="EmployeeID" Type="Int32" Nullable="false"/>

        <Property Name="NationalIDNumber" Type="String" Nullable="false" MaxLength="15" />

        <Property Name="LoginID" Type="String" Nullable="false" MaxLength="256" />

        <Property Name="EmployeeTitle" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="BirthDate" Type="DateTime" Nullable="false" />

        <Property Name="MaritalStatus" Type="String" Nullable="false" MaxLength="1" FixedLength="true" />

        <Property Name="Gender" Type="String" Nullable="false" MaxLength="1" FixedLength="true" />

        <Property Name="HireDate" Type="DateTime" Nullable="false" />

        <Property Name="SalariedFlag" Type="Boolean" Nullable="false" />

        <Property Name="VacationHours" Type="Int16" Nullable="false" />

        <Property Name="SickLeaveHours" Type="Int16" Nullable="false" />

        <Property Name="CurrentFlag" Type="Boolean" Nullable="false" />

        <Property Name="Employee_rowguid" Type="Guid" Nullable="false" />

        <Property Name="Employee_ModifiedDate" Type="DateTime" Nullable="false" />

        <Property Name="NameStyle" Type="Boolean" Nullable="false" />

        <Property Name="Title" Type="String" MaxLength="8" />

        <Property Name="FirstName" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="MiddleName" Type="String" MaxLength="50" />

        <Property Name="LastName" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="Suffix" Type="String" MaxLength="10" />

        <Property Name="EmailAddress" Type="String" MaxLength="50" />

        <Property Name="EmailPromotion" Type="Int32" Nullable="false" />

        <Property Name="Phone" Type="String" MaxLength="25" />

        <Property Name="PasswordHash" Type="String" Nullable="false" MaxLength="128" Unicode="false" />

        <Property Name="PasswordSalt" Type="String" Nullable="false" MaxLength="10" Unicode="false" />

        <Property Name="rowguid" Type="Guid" Nullable="false" />

        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />

      </EntityType>

    </Schema>

     

    EntitySplitting Mapping (MSL):

    The following XML describes the mapping of the single Employee EntityType to two different tables in the AdventureWorks storage schema.  Note the use of MappingFragments to describe the fields mapped to each table.

     

    Entity Splitting Mapping Definition (MSL)

    <?xml version="1.0" encoding="utf-8"?>

    <Mapping xmlns:cs="urn:schemas-microsoft-com:windows:storage:mapping:CS" cs:Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">

    <cs:EntityContainerMapping cs:StorageEntityContainer="HumanResources" cs:CdmEntityContainer="AdventureWorksEntities">

     <cs:EntitySetMapping cs:Name="Employees" cs:TypeName="AdventureWorksModel_Splitting.Employee">

       <cs:TableMappingFragment cs:TableName="Contact">         

         <cs:ScalarProperty cs:Name="ContactID" cs:ColumnName="ContactID" />

         <cs:ScalarProperty cs:Name="NameStyle" cs:ColumnName="NameStyle" />

         <cs:ScalarProperty cs:Name="Title" cs:ColumnName="Title" />

         <cs:ScalarProperty cs:Name="FirstName" cs:ColumnName="FirstName" />

         <cs:ScalarProperty cs:Name="MiddleName" cs:ColumnName="MiddleName" />

         <cs:ScalarProperty cs:Name="LastName" cs:ColumnName="LastName" />

         <cs:ScalarProperty cs:Name="Suffix" cs:ColumnName="Suffix" />

         <cs:ScalarProperty cs:Name="EmailAddress" cs:ColumnName="EmailAddress" />

         <cs:ScalarProperty cs:Name="EmailPromotion" cs:ColumnName="EmailPromotion" />

         <cs:ScalarProperty cs:Name="Phone" cs:ColumnName="Phone" />

         <cs:ScalarProperty cs:Name="PasswordHash" cs:ColumnName="PasswordHash" />

         <cs:ScalarProperty cs:Name="PasswordSalt" cs:ColumnName="PasswordSalt" />

         <cs:ScalarProperty cs:Name="rowguid" cs:ColumnName="rowguid" />

         <cs:ScalarProperty cs:Name="ModifiedDate" cs:ColumnName="ModifiedDate" />

       </cs:TableMappingFragment>

       <cs:TableMappingFragment cs:TableName="Employee">

         <cs:ScalarProperty cs:Name="ContactID" cs:ColumnName="ContactID" />

         <cs:ScalarProperty cs:Name="EmployeeID" cs:ColumnName="EmployeeID" />

         <cs:ScalarProperty cs:Name="NationalIDNumber" cs:ColumnName="NationalIDNumber" />

         <cs:ScalarProperty cs:Name="LoginID" cs:ColumnName="LoginID" />

         <cs:ScalarProperty cs:Name="EmployeeTitle" cs:ColumnName="Title" />

         <cs:ScalarProperty cs:Name="BirthDate" cs:ColumnName="BirthDate" />

         <cs:ScalarProperty cs:Name="MaritalStatus" cs:ColumnName="MaritalStatus" />

         <cs:ScalarProperty cs:Name="Gender" cs:ColumnName="Gender" />

         <cs:ScalarProperty cs:Name="HireDate" cs:ColumnName="HireDate" />

         <cs:ScalarProperty cs:Name="SalariedFlag" cs:ColumnName="SalariedFlag" />

         <cs:ScalarProperty cs:Name="VacationHours" cs:ColumnName="VacationHours" />

         <cs:ScalarProperty cs:Name="SickLeaveHours" cs:ColumnName="SickLeaveHours" />

         <cs:ScalarProperty cs:Name="CurrentFlag" cs:ColumnName="CurrentFlag" />

         <cs:ScalarProperty cs:Name="Employee_rowguid" cs:ColumnName="rowguid" />

         <cs:ScalarProperty cs:Name="Employee_ModifiedDate" cs:ColumnName="ModifiedDate" />

       </cs:TableMappingFragment>

      </cs:EntitySetMapping>

     </cs:EntityContainerMapping> 

    </Mapping>

     

    EntitySplitting Example:

    Finally, the following example shows something similar to the code I believe you were trying to write, where you query for employees and are able to access properties defined either in the Employee or Contact table:

    Entity Splitting Example

     

        Sub DoSplitting()

            Dim a As New AdventureWorksEntities( _

    "name=AdventureWorksEntities_Splitting")

            Dim employee = a.CreateQuery(Of Employee)( _

    "SELECT VALUE p FROM employees AS p")

            For Each p In employee

                Console.WriteLine("{0} {1} {2}", _

    p.EmployeeID, p.FirstName, p.LastName)

            Next

            Console.ReadLine()

        End Sub

     

    Hopefully this helps explain a couple of options for mapping a single entity (Employee) to two different tables within your store.

    Best of Luck!
    -Mike

    Thursday, June 21, 2007 1:16 AM
  • The SSDL defines how the EntityClient sees the store.  Since ContactID is a unique key for both Employee and Contact, it's fine to use it as the primary key.  It does, however, make relationships a bit difficult in Beta 1, since we don't support relationships between subtypes so you can't have a relationship that uses the EmployeeID field since it's not defined on the base type (the AdventureWorks schema is a bit funky in how it uses different keys for EmployeeID and ContactID).  We'll be supporting relationships on subtypes in our next public release CTP, so that should enable you to round out the sample...

     

    As far as when to use entity splitting/inheritance and when to use associations and navigation properties:

    Associations/Navigation Properties: Associations and Navigation Propertiesare used between two independent entities; for example, customer and orders.  They allow different cardinalities, for example 1:1, 1:Many, Many:Many.

    Inheritance: Inheritance is used when multiple types share a common set of properties.  For example, Customers and Employees are different EntityTypes, but share fields like first name, last name, Address, etc.

    Entity Splitting: Entity Splitting (mapping a single entity to multiple tables) is used when the properties for one logical entity comes from two different tables that share a common key, and there is no useful inheritance representation betweeen them (i.e., you're not interested in modeling other types that have a common subtype).

     

    We will also be introducing ComplexTypes shortly.  Complex types provide the ability to package a set of properties on an EntityType as a single composite, or "Complex" type.  For example, you could group FirstName and LastName together as a "Name" property on Contact, where the Name property had properties for FirstName and LastName. Note that the complex type is not an entity, because it does not have its own key.

     

    Thursday, June 21, 2007 5:07 PM

All replies

  • Matelin,

     

    Your Entity SQL string may need a little refinement. Is AdventureWorksConnection the container name within the CSDL file? When I add AdventureWorks and choose all the defaults, the name of the container in my project is AdventureWorksEntities. You may want to check, then switch out the container name, or better yet just remove the container name to leave Employees.

     

    If that doesn't help, can you post your csdl file? Below is the code that worked for me.

     

    -Brian

     

    Dim a As New AdventureWorksEntities

    Dim employee = a.CreateQuery(Of Employee)("SELECT VALUE p FROM Employee AS p")

    For Each p In employee

          ListBox1.Items.Add(p.EmployeeID.ToString)

    Next

    Monday, June 18, 2007 2:38 PM
  • If you used EDMGen or the Wizard to generate your entity model from Adventureworks, it will generate Employees and Contact as two separate base EntityTypes.  We don't, by default, infer the inheritance relationship between Employee and Contact. We should derive a 1:1 relationship between Employee and Contact that you can navigate to get to the properties defined in Contact, but I suspect you really want to view these as an inheritance relationship.

     

    We are working on a more full fledged entity designer that will allow you to visually define mappings and inheritance; in the meantime you'll have to modify the mapping files by hand. As soon as I get a chance I'll post sample CSDL and MSL for AdventureWorks that show mapping Employees and Contact where Employees derives from Contact.

    Monday, June 18, 2007 9:45 PM
  • Okay; here are the sample mappings.

     

    One way to map this would be as inheritance; Employees derive from Contacts.  This is how the Adventureworks schema is laid out, and is useful if you intend on including other entity types that derive from Contacts in your model (for example, a Customer, a VendorContact, etc...).

     

    The second way to map this would be through "EntitySplitting", by mapping the Employee entity to columns in both Employees and Contacts tables.  This method would be useful if you model was just dealing with Employees as employees, and not interested in other types of contacts.

     

    Both sets of mappings are shown below, using Orcas Beta 1:

     

    SSDL

    In order for Employee to derive from Contact, or to map Employee to both Contact and Employee tables, Contact and Employee must share the same key.  Below I've made ContactID the  Key for both the Contact type and the Employee type.

    Storage Schema Definition (SSDL)

     

    <?xml version="1.0" encoding="utf-8"?>

    <Schema Namespace="AdventureWorks" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">

      <EntityContainer Name="HumanResources">

        <EntitySet Name="Employee" EntityType="AdventureWorks.Employee" />

        <EntitySet Name="Contact" EntityType="AdventureWorks.Contact" Schema="Person" />

      </EntityContainer>

      <EntityType Name="Employee" Key="ContactID">

        <Property Name="EmployeeID" Type="int" Nullable="false" StoreGeneratedPattern="identity" />

        <Property Name="NationalIDNumber" Type="nvarchar" Nullable="false" MaxLength="15" />

        <Property Name="ContactID" Type="int" Nullable="false" />

        <Property Name="LoginID" Type="nvarchar" Nullable="false" MaxLength="256" />

        <Property Name="ManagerID" Type="int" />

        <Property Name="Title" Type="nvarchar" Nullable="false" MaxLength="50" />

        <Property Name="BirthDate" Type="datetime" Nullable="false" />

        <Property Name="MaritalStatus" Type="nchar" Nullable="false" MaxLength="1" />

        <Property Name="Gender" Type="nchar" Nullable="false" MaxLength="1" />

        <Property Name="HireDate" Type="datetime" Nullable="false" />

        <Property Name="SalariedFlag" Type="bit" Nullable="false" />

        <Property Name="VacationHours" Type="smallint" Nullable="false" />

        <Property Name="SickLeaveHours" Type="smallint" Nullable="false" />

        <Property Name="CurrentFlag" Type="bit" Nullable="false" />

        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />

        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />

      </EntityType>

      <EntityType Name="Contact" Key="ContactID">

        <Property Name="ContactID" Type="int" Nullable="false" StoreGeneratedPattern="identity" />

        <Property Name="NameStyle" Type="bit" Nullable="false" />

        <Property Name="Title" Type="nvarchar" MaxLength="8" />

        <Property Name="FirstName" Type="nvarchar" Nullable="false" MaxLength="50" />

        <Property Name="MiddleName" Type="nvarchar" MaxLength="50" />

        <Property Name="LastName" Type="nvarchar" Nullable="false" MaxLength="50" />

        <Property Name="Suffix" Type="nvarchar" MaxLength="10" />

        <Property Name="EmailAddress" Type="nvarchar" MaxLength="50" />

        <Property Name="EmailPromotion" Type="int" Nullable="false" />

        <Property Name="Phone" Type="nvarchar" MaxLength="25" />

        <Property Name="PasswordHash" Type="varchar" Nullable="false" MaxLength="128" />

        <Property Name="PasswordSalt" Type="varchar" Nullable="false" MaxLength="10" />

        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />

        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />

      </EntityType>

    </Schema> 

     

    Inheritance Conceptual Model (CSDL):

    The following XML describes the conceptual model where Employee derives from Contact (note the use of BaseType in the definition of the Employee EntityType.

    Inheritance Conceptual Schema Definition (CSDL)

     

    <?xml version="1.0" encoding="utf-8"?>

    <Schema Namespace="AdventureWorksModel_Inheritance" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">

      <EntityContainer Name="AdventureWorksEntities">

        <EntitySet Name="Contacts" EntityType="AdventureWorksModel_Inheritance.Contact" />

      </EntityContainer>

      <EntityType Name="Contact" Key="ContactID">     

        <Property Name="ContactID" Type="Int32" Nullable="false" />

        <Property Name="NameStyle" Type="Boolean" Nullable="false" />

        <Property Name="Title" Type="String" MaxLength="8" />

        <Property Name="FirstName" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="MiddleName" Type="String" MaxLength="50" />

        <Property Name="LastName" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="Suffix" Type="String" MaxLength="10" />

        <Property Name="EmailAddress" Type="String" MaxLength="50" />

        <Property Name="EmailPromotion" Type="Int32" Nullable="false" />

        <Property Name="Phone" Type="String" MaxLength="25" />

        <Property Name="PasswordHash" Type="String" Nullable="false" MaxLength="128" Unicode="false" />

        <Property Name="PasswordSalt" Type="String" Nullable="false" MaxLength="10" Unicode="false" />

        <Property Name="rowguid" Type="Guid" Nullable="false" />

        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />

      </EntityType>

      <EntityType Name="Employee" BaseType="Self.Contact">

        <Property Name="EmployeeID" Type="Int32" Nullable="false" />

        <Property Name="NationalIDNumber" Type="String" Nullable="false" MaxLength="15" />

        <Property Name="LoginID" Type="String" Nullable="false" MaxLength="256" />

        <Property Name="EmployeeTitle" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="BirthDate" Type="DateTime" Nullable="false" />

        <Property Name="MaritalStatus" Type="String" Nullable="false" MaxLength="1" FixedLength="true" />

        <Property Name="Gender" Type="String" Nullable="false" MaxLength="1" FixedLength="true" />

        <Property Name="HireDate" Type="DateTime" Nullable="false" />

        <Property Name="SalariedFlag" Type="Boolean" Nullable="false" />

        <Property Name="VacationHours" Type="Int16" Nullable="false" />

        <Property Name="SickLeaveHours" Type="Int16" Nullable="false" />

        <Property Name="CurrentFlag" Type="Boolean" Nullable="false" />

        <Property Name="Employee_rowguid" Type="Guid" Nullable="false" />

        <Property Name="Employee_ModifiedDate" Type="DateTime" Nullable="false" />

      </EntityType>

     </Schema>

     

    Inheritance Mapping (MSL):

    The mapping file for inheritance shows both Employee and Contact mapped to the same EntitySet (Contacts).  Note that the TypeName for the Contact EntityTypeMapping is "IsTypeOf(Contact)", meaning that this is the mapping for the base type Contact.

    Inheritance Mapping Definition (MSL)

     

    <?xml version="1.0" encoding="utf-8"?>

    <Mapping xmlns:cs="urn:schemas-microsoft-com:windows:storage:mapping:CS" cs:Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">

    <cs:EntityContainerMapping cs:StorageEntityContainer="HumanResources" cs:CdmEntityContainer="AdventureWorksEntities">

     <cs:EntitySetMapping cs:Name="Contacts" >

      <cs:EntityTypeMapping cs:TypeName="IsTypeOf(AdventureWorksModel_Inheritance.Contact)">

        <cs:TableMappingFragment cs:TableName="Contact">         

          <cs:ScalarProperty cs:Name="ContactID" cs:ColumnName="ContactID" />

          <cs:ScalarProperty cs:Name="NameStyle" cs:ColumnName="NameStyle" />

          <cs:ScalarProperty cs:Name="Title" cs:ColumnName="Title" />

          <cs:ScalarProperty cs:Name="FirstName" cs:ColumnName="FirstName" />

          <cs:ScalarProperty cs:Name="MiddleName" cs:ColumnName="MiddleName" />

          <cs:ScalarProperty cs:Name="LastName" cs:ColumnName="LastName" />

          <cs:ScalarProperty cs:Name="Suffix" cs:ColumnName="Suffix" />

          <cs:ScalarProperty cs:Name="EmailAddress" cs:ColumnName="EmailAddress" />

          <cs:ScalarProperty cs:Name="EmailPromotion" cs:ColumnName="EmailPromotion" />

          <cs:ScalarProperty cs:Name="Phone" cs:ColumnName="Phone" />

          <cs:ScalarProperty cs:Name="PasswordHash" cs:ColumnName="PasswordHash" />

          <cs:ScalarProperty cs:Name="PasswordSalt" cs:ColumnName="PasswordSalt" />

          <cs:ScalarProperty cs:Name="rowguid" cs:ColumnName="rowguid" />

          <cs:ScalarProperty cs:Name="ModifiedDate" cs:ColumnName="ModifiedDate" />

        </cs:TableMappingFragment>

      </cs:EntityTypeMapping>

      <cs:EntityTypeMapping cs:TypeName="AdventureWorksModel_Inheritance.Employee">

        <cs:TableMappingFragment cs:TableName="Employee">

          <cs:ScalarProperty cs:Name="ContactID" cs:ColumnName="ContactID" />

          <cs:ScalarProperty cs:Name="EmployeeID" cs:ColumnName="EmployeeID" />

          <cs:ScalarProperty cs:Name="NationalIDNumber" cs:ColumnName="NationalIDNumber" />

          <cs:ScalarProperty cs:Name="LoginID" cs:ColumnName="LoginID" />

          <cs:ScalarProperty cs:Name="EmployeeTitle" cs:ColumnName="Title" />

          <cs:ScalarProperty cs:Name="BirthDate" cs:ColumnName="BirthDate" />

          <cs:ScalarProperty cs:Name="MaritalStatus" cs:ColumnName="MaritalStatus" />

          <cs:ScalarProperty cs:Name="Gender" cs:ColumnName="Gender" />

          <cs:ScalarProperty cs:Name="HireDate" cs:ColumnName="HireDate" />

          <cs:ScalarProperty cs:Name="SalariedFlag" cs:ColumnName="SalariedFlag" />

          <cs:ScalarProperty cs:Name="VacationHours" cs:ColumnName="VacationHours" />

          <cs:ScalarProperty cs:Name="SickLeaveHours" cs:ColumnName="SickLeaveHours" />

          <cs:ScalarProperty cs:Name="CurrentFlag" cs:ColumnName="CurrentFlag" />

          <cs:ScalarProperty cs:Name="Employee_rowguid" cs:ColumnName="rowguid" />

          <cs:ScalarProperty cs:Name="Employee_ModifiedDate" cs:ColumnName="ModifiedDate" />

        </cs:TableMappingFragment>

      </cs:EntityTypeMapping>

     </cs:EntitySetMapping>

    </cs:EntityContainerMapping> 

    </Mapping>

     

     Inheritance Example: 

    The following code shows querying only for those contacts that are employees, and accessing both contact and employee properties on the result.  Because a query against the Contacts table could return a any contact (whether it is an employee or not), we use the Is Of (type) operator to limit the results to employees, and the Treat() operator to return the results as employees, rather than just Contacts. 

    Inheritance Example

     

        Sub DoInheritance()

            Dim a As New AdventureWorksEntities( _

              "name=AdventureWorksEntities_Inheritance")

            Dim employee = a.CreateQuery(Of Employee)( _

              "SELECT VALUE treat(p as AdventureWorksModel_Inheritance.Employee) " & _

    FROM contacts AS p " & _

              "WHERE p Is Of (AdventureWorksModel_Inheritance.Employee)")

            For Each p In employee

                Console.WriteLine("{0} {1} {2}", _

    p.EmployeeID, p.FirstName, p.LastName)

            Next

            Console.ReadLine()

        End Sub

     

    This mapping would be useful if you wanted to sometimes query for Contacts that weren’t employees. Alternatively, if you were only interested in Employees, there would be no reason to include Contacts as the base entity type in your mapping, and you could simply map the Employee entity type to both Employee and Contacts tables, as shown in the following example.

     

    EntitySplitting SSDL:

    In the case of EntitySplitting (mapping Employee to both Employee and Customer tables) I can use the same ssdl as in the previous example.

     

    EntitySplitting Conceptual Model (CSDL):

    The following XML describes a conceptual schema with a simple Employee type that maps to an Employees table with no inheritance.  Note that, again, ContactID is used as the key since it is a common key across contacts and employees.

    Entity Splitting Conceptual Model (CSDL)

     

    <?xml version="1.0" encoding="utf-8"?>

    <Schema Namespace="AdventureWorksModel_Splitting" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">

      <EntityContainer Name="AdventureWorksEntities">

        <EntitySet Name="Employees" EntityType="AdventureWorksModel_Splitting.Employee" />

      </EntityContainer>

      <EntityType Name="Employee" Key="ContactID">

        <Property Name="ContactID" Type="Int32" Nullable="false" />

        <Property Name="EmployeeID" Type="Int32" Nullable="false"/>

        <Property Name="NationalIDNumber" Type="String" Nullable="false" MaxLength="15" />

        <Property Name="LoginID" Type="String" Nullable="false" MaxLength="256" />

        <Property Name="EmployeeTitle" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="BirthDate" Type="DateTime" Nullable="false" />

        <Property Name="MaritalStatus" Type="String" Nullable="false" MaxLength="1" FixedLength="true" />

        <Property Name="Gender" Type="String" Nullable="false" MaxLength="1" FixedLength="true" />

        <Property Name="HireDate" Type="DateTime" Nullable="false" />

        <Property Name="SalariedFlag" Type="Boolean" Nullable="false" />

        <Property Name="VacationHours" Type="Int16" Nullable="false" />

        <Property Name="SickLeaveHours" Type="Int16" Nullable="false" />

        <Property Name="CurrentFlag" Type="Boolean" Nullable="false" />

        <Property Name="Employee_rowguid" Type="Guid" Nullable="false" />

        <Property Name="Employee_ModifiedDate" Type="DateTime" Nullable="false" />

        <Property Name="NameStyle" Type="Boolean" Nullable="false" />

        <Property Name="Title" Type="String" MaxLength="8" />

        <Property Name="FirstName" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="MiddleName" Type="String" MaxLength="50" />

        <Property Name="LastName" Type="String" Nullable="false" MaxLength="50" />

        <Property Name="Suffix" Type="String" MaxLength="10" />

        <Property Name="EmailAddress" Type="String" MaxLength="50" />

        <Property Name="EmailPromotion" Type="Int32" Nullable="false" />

        <Property Name="Phone" Type="String" MaxLength="25" />

        <Property Name="PasswordHash" Type="String" Nullable="false" MaxLength="128" Unicode="false" />

        <Property Name="PasswordSalt" Type="String" Nullable="false" MaxLength="10" Unicode="false" />

        <Property Name="rowguid" Type="Guid" Nullable="false" />

        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />

      </EntityType>

    </Schema>

     

    EntitySplitting Mapping (MSL):

    The following XML describes the mapping of the single Employee EntityType to two different tables in the AdventureWorks storage schema.  Note the use of MappingFragments to describe the fields mapped to each table.

     

    Entity Splitting Mapping Definition (MSL)

    <?xml version="1.0" encoding="utf-8"?>

    <Mapping xmlns:cs="urn:schemas-microsoft-com:windows:storage:mapping:CS" cs:Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">

    <cs:EntityContainerMapping cs:StorageEntityContainer="HumanResources" cs:CdmEntityContainer="AdventureWorksEntities">

     <cs:EntitySetMapping cs:Name="Employees" cs:TypeName="AdventureWorksModel_Splitting.Employee">

       <cs:TableMappingFragment cs:TableName="Contact">         

         <cs:ScalarProperty cs:Name="ContactID" cs:ColumnName="ContactID" />

         <cs:ScalarProperty cs:Name="NameStyle" cs:ColumnName="NameStyle" />

         <cs:ScalarProperty cs:Name="Title" cs:ColumnName="Title" />

         <cs:ScalarProperty cs:Name="FirstName" cs:ColumnName="FirstName" />

         <cs:ScalarProperty cs:Name="MiddleName" cs:ColumnName="MiddleName" />

         <cs:ScalarProperty cs:Name="LastName" cs:ColumnName="LastName" />

         <cs:ScalarProperty cs:Name="Suffix" cs:ColumnName="Suffix" />

         <cs:ScalarProperty cs:Name="EmailAddress" cs:ColumnName="EmailAddress" />

         <cs:ScalarProperty cs:Name="EmailPromotion" cs:ColumnName="EmailPromotion" />

         <cs:ScalarProperty cs:Name="Phone" cs:ColumnName="Phone" />

         <cs:ScalarProperty cs:Name="PasswordHash" cs:ColumnName="PasswordHash" />

         <cs:ScalarProperty cs:Name="PasswordSalt" cs:ColumnName="PasswordSalt" />

         <cs:ScalarProperty cs:Name="rowguid" cs:ColumnName="rowguid" />

         <cs:ScalarProperty cs:Name="ModifiedDate" cs:ColumnName="ModifiedDate" />

       </cs:TableMappingFragment>

       <cs:TableMappingFragment cs:TableName="Employee">

         <cs:ScalarProperty cs:Name="ContactID" cs:ColumnName="ContactID" />

         <cs:ScalarProperty cs:Name="EmployeeID" cs:ColumnName="EmployeeID" />

         <cs:ScalarProperty cs:Name="NationalIDNumber" cs:ColumnName="NationalIDNumber" />

         <cs:ScalarProperty cs:Name="LoginID" cs:ColumnName="LoginID" />

         <cs:ScalarProperty cs:Name="EmployeeTitle" cs:ColumnName="Title" />

         <cs:ScalarProperty cs:Name="BirthDate" cs:ColumnName="BirthDate" />

         <cs:ScalarProperty cs:Name="MaritalStatus" cs:ColumnName="MaritalStatus" />

         <cs:ScalarProperty cs:Name="Gender" cs:ColumnName="Gender" />

         <cs:ScalarProperty cs:Name="HireDate" cs:ColumnName="HireDate" />

         <cs:ScalarProperty cs:Name="SalariedFlag" cs:ColumnName="SalariedFlag" />

         <cs:ScalarProperty cs:Name="VacationHours" cs:ColumnName="VacationHours" />

         <cs:ScalarProperty cs:Name="SickLeaveHours" cs:ColumnName="SickLeaveHours" />

         <cs:ScalarProperty cs:Name="CurrentFlag" cs:ColumnName="CurrentFlag" />

         <cs:ScalarProperty cs:Name="Employee_rowguid" cs:ColumnName="rowguid" />

         <cs:ScalarProperty cs:Name="Employee_ModifiedDate" cs:ColumnName="ModifiedDate" />

       </cs:TableMappingFragment>

      </cs:EntitySetMapping>

     </cs:EntityContainerMapping> 

    </Mapping>

     

    EntitySplitting Example:

    Finally, the following example shows something similar to the code I believe you were trying to write, where you query for employees and are able to access properties defined either in the Employee or Contact table:

    Entity Splitting Example

     

        Sub DoSplitting()

            Dim a As New AdventureWorksEntities( _

    "name=AdventureWorksEntities_Splitting")

            Dim employee = a.CreateQuery(Of Employee)( _

    "SELECT VALUE p FROM employees AS p")

            For Each p In employee

                Console.WriteLine("{0} {1} {2}", _

    p.EmployeeID, p.FirstName, p.LastName)

            Next

            Console.ReadLine()

        End Sub

     

    Hopefully this helps explain a couple of options for mapping a single entity (Employee) to two different tables within your store.

    Best of Luck!
    -Mike

    Thursday, June 21, 2007 1:16 AM
  •  

    Thanx u Michael Pizzo  it Greaaaaaaaaaaaaaaaaaaaaaat Sample

     

    but i have some issue in my mind

    - when u have wrote the SSDL above u changed the Key of the employee table from employee Id to Contact Id and i undersatnd why  u  did that.. but i know that SSDL file is an exact representation of the DB so it okay to change it(or its okay to change the key only)

     

    - with the above 2 great methods i can work with relationship in database so where i should use the  Associations type and

    navigation property

     

    Brian

    it its a pasting error 

     

     

    Best Regards

    Matelin

    Thursday, June 21, 2007 2:10 PM
  • The SSDL defines how the EntityClient sees the store.  Since ContactID is a unique key for both Employee and Contact, it's fine to use it as the primary key.  It does, however, make relationships a bit difficult in Beta 1, since we don't support relationships between subtypes so you can't have a relationship that uses the EmployeeID field since it's not defined on the base type (the AdventureWorks schema is a bit funky in how it uses different keys for EmployeeID and ContactID).  We'll be supporting relationships on subtypes in our next public release CTP, so that should enable you to round out the sample...

     

    As far as when to use entity splitting/inheritance and when to use associations and navigation properties:

    Associations/Navigation Properties: Associations and Navigation Propertiesare used between two independent entities; for example, customer and orders.  They allow different cardinalities, for example 1:1, 1:Many, Many:Many.

    Inheritance: Inheritance is used when multiple types share a common set of properties.  For example, Customers and Employees are different EntityTypes, but share fields like first name, last name, Address, etc.

    Entity Splitting: Entity Splitting (mapping a single entity to multiple tables) is used when the properties for one logical entity comes from two different tables that share a common key, and there is no useful inheritance representation betweeen them (i.e., you're not interested in modeling other types that have a common subtype).

     

    We will also be introducing ComplexTypes shortly.  Complex types provide the ability to package a set of properties on an EntityType as a single composite, or "Complex" type.  For example, you could group FirstName and LastName together as a "Name" property on Contact, where the Name property had properties for FirstName and LastName. Note that the complex type is not an entity, because it does not have its own key.

     

    Thursday, June 21, 2007 5:07 PM
  • I have problem with modifying CSDL and MSL files: When I introduce inheritance and try to generate cs code, EdmGen /mode:EntityClassGeneration returns:

    Prototype.csdl(127,8) : error 0100: The End Individual has a different Type than the EntitySet it refers to.
    Prototype.csdl(194,8) : error 0100: The End Individual has a different Type than the EntitySet it refers to.

    First EdmGen has generated 1:1 mappings for two entities: InvolvedParty and Individual within two EntitySets. Then I've made inheritance and mappings:

    CSDL (fragment):

    <?xml version="1.0" encoding="utf-8"?>
    <Schema Namespace="EdmModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
      <EntityContainer Name="Prototype">
          
        <!--EntitySet Name="Individual" EntityType="EdmModel.Individual" /-->
        <EntitySet Name="InvolvedParties" EntityType="EdmModel.InvolvedParty" />
          
        <AssociationSet Name="birthplace" Association="EdmModel.birthplace">
          <End Role="Place" EntitySet="Place" />
          <End Role="Individual" EntitySet="InvolvedParties" />
        </AssociationSet>
        <AssociationSet Name="FK_contactingPersonPreference_Individual" Association="EdmModel.FK_contactingPersonPreference_Individual">
          <End Role="Individual" EntitySet="InvolvedParties" />
          <End Role="contactingPersonPreference" EntitySet="contactingPersonPreference" />
        </AssociationSet>
      </EntityContainer>
        
      <EntityType Name="InvolvedParty" Key="ID">
        <Property Name="ID" Type="Int64" Nullable="false" />
        <!-- ... -->
      </EntityType>
        
      <!--EntityType Name="Individual" Key="ID"-->
      <EntityType Name="Individual" BaseType="EdmModel.InvolvedParty">
        <!--Property Name="ID" Type="Int64" Nullable="false" /-->
        <!-- ... -->
        <NavigationProperty Name="Place" Relationship="EdmModel.birthplace" FromRole="Individual" ToRole="Place" />
        <NavigationProperty Name="contactingPersonPreference" Relationship="EdmModel.FK_contactingPersonPreference_Individual" FromRole="Individual" ToRole="contactingPersonPreference" />
      </EntityType>
        
      <Association Name="birthplace">
        <End Role="Place" Type="EdmModel.Place" Multiplicity="0..1" />
        <End Role="Individual" Type="EdmModel.Individual" Multiplicity="*" />
      </Association>

      <Association Name="FK_contactingPersonPreference_Individual">
        <End Role="Individual" Type="EdmModel.Individual" Multiplicity="1..1" />
        <End Role="contactingPersonPreference" Type="EdmModel.contactingPersonPreference" Multiplicity="*" />
      </Association>

    </Schema>

    MSL (fragment):

    <?xml version="1.0" encoding="utf-8"?>
    <Mapping xmlns:cs="urnTongue Tiedchemas-microsoft-com:windowsTongue Tiedtorage:mapping:CS" csTongue Tiedpace="C-S" xmlns="urnTongue Tiedchemas-microsoft-com:windowsTongue Tiedtorage:mapping:CS">
        <cs:EntityContainerMapping csTongue TiedtorageEntityContainer="dbo" cs:CdmEntityContainer="Prototype">

            <!--cs:EntitySetMapping cs:Name="InvolvedParty" cs:TableName="InvolvedParty" cs:TypeName="EdmModel.InvolvedParty">
                <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="ID" />
                < ... >
            </cs:EntitySetMapping--
    >

            <!--cs:EntitySetMapping cs:Name="Individual" cs:TableName="Individual" cs:TypeName="EdmModel.Individual">
                <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="ID" />
                < ... >
            </cs:EntitySetMapping--
    >

            <cs:EntitySetMapping cs:Name="InvolvedParties">
                <cs:EntityTypeMapping cs:TypeName="EdmModel.InvolvedParty">
                    <cs:TableMappingFragment cs:TableName="InvolvedParty">
                        <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="ID"/>
                        <!-- ... -->
                    </cs:TableMappingFragment>
                </cs:EntityTypeMapping>
                <cs:EntityTypeMapping cs:TypeName="EdmModel.Individual">
                    <cs:TableMappingFragment cs:TableName="Individual">
                        <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="ID"/>
                        <!-- ... -->
                    </cs:TableMappingFragment>
                    <cs:TableMappingFragment cs:TableName="InvolvedParty">
                        <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="ID"/>
                        <!-- ... -->
                    </cs:TableMappingFragment>
                </cs:EntityTypeMapping>
            </cs:EntitySetMapping>

            <cs:AssociationSetMapping cs:Name="birthplace" cs:TypeName="EdmModel.birthplace" cs:TableName="Individual">
                <cs:EndProperty cs:Name="Place">
                    <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="hasBirthplace"/>
                </cs:EndProperty>
                <cs:EndProperty cs:Name="Individual">
                    <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="ID"/>
                </cs:EndProperty>
                <cs:Condition cs:ColumnName="hasBirthplace" cs:IsNull="false"/>
            </cs:AssociationSetMapping>

            <cs:AssociationSetMapping cs:Name="FK_contactingPersonPreference_Individual" cs:TypeName="EdmModel.FK_contactingPersonPreference_Individual" cs:TableName="contactingPersonPreference">
                <cs:EndProperty cs:Name="Individual">
                    <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="Individual_ID"/>
                </cs:EndProperty>
                <cs:EndProperty cs:Name="contactingPersonPreference">
                    <csTongue TiedcalarProperty cs:Name="ID" cs:ColumnName="ID"/>
                </cs:EndProperty>
                <cs:Condition cs:ColumnName="Individual_ID" cs:IsNull="false"/>
            </cs:AssociationSetMapping>
        </cs:EntityContainerMapping>
    </Mapping>

    (Orcas Beta1 May CTP)
    Wednesday, July 4, 2007 7:56 AM
  • I'm going to bet that you are not yet using the most recently released June CTP...

     

    I think the problem you are encountering is that before the June CTP we did not allow the definition of associations where the types of the ends were different from the base type of the entityset they participated in.  So, in your case you could not make an association where one end is an Individual because your entityset is of InvolvedParty and Individual inherits from that.  In the June CTP, however, we added this support.  So, if you upgrade to the new CTP, this issue should go away.

    Wednesday, July 4, 2007 5:39 PM
  • After painful June CTP installation, it worked. (But still in pains - with Visual Web Developer.)

        <EntityContainer Name="FsidmSimpleContext">
        
        <EntitySet Name="InvolvedParties" EntityType="FsidmSimple.InvolvedParty" />
        <!--EntitySet Name="Individual" EntityType="FsidmSimple.Individual" /-->
        <EntitySet Name="Place" EntityType="FsidmSimple.Place" />
        
        <AssociationSet Name="birthplace" Association="FsidmSimple.birthplace">
          <End Role="Place" EntitySet="Place" />
          <End Role="Individual" EntitySet="InvolvedParties" />
        </AssociationSet>
        
      </EntityContainer>

    Tricky part was to declare Role="Individual" in EntitySet="InvolvedParties" while it is not obvious that entity Individual is contained in EntitySet InvolvedParties. (It is inherited from  InvolvedParties' base class InvolvedParty.

    Would Orcas Beta 2 will support those new features that came with ADO.NET EF June CTP?

    Is there any way to configure Orcas Beta 1 to work with June CTP editions of .NET Framework and ADO.NET EF?
    Thursday, July 5, 2007 4:01 PM
  • There will be an entity framework CTP that is released shortly after orcas beta 2 which will layer on top of beta 2 and include all of the current CTP's freatures plus a few more.  Unfortunately it's not possible for the June CTP to work with beta 1, because the June CTP is based on changes to the framework which came after beta 1.  We undersand that the web developer release does not contain all of the features that folks would like to test, but it was the only release vehicle for the version of the framework that we need at this time, so we thought it was better to get the June CTP out so that folks could try it now rather than wait until we can release another CTP after beta 2...

     

    - Danny

    Friday, July 6, 2007 3:24 PM