locked
Entity splitting with 2 tables RRS feed

  • Question

  • Hi,

    i have a problem with splitting entities on my database tables. I've got this tables in my database:

    User - PremiumUser - PremiumAccount

    Here you can see an image of it:
     

    And know i want to splitt the PremiumUser Entity over User and PremiumUser table. I've copied the scalar properties from the User entity to the PremiumUser Entity an have mapped the PremiumUser entity to the Users table. With this scenario i got an error 3024.

    What i want ist an User entity and a PremiumUser entity, which is mapped to the User entity, so i can get all the properties direct from it. I have tried to create a new entity which inherits from the user entity and then map it to the premiumuser entity, but this doesn't work, too.

    Maybe one of you can help me find the right way to do this. I would appreciate it.

    Thanks a lot - Mariusz

    Saturday, January 10, 2009 12:53 PM

Answers

  • Here you go:

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

    <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">

    <!-- EF Runtime content -->

    <edmx:Runtime>

    <!-- SSDL content -->

    <edmx:StorageModels>

    <Schema Namespace="kjModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">

    <EntityContainer Name="kjModelStoreContainer">

    <EntitySet Name="Contacts" EntityType="kjModel.Store.Contacts" store:Type="Tables" Schema="dbo" />

    <EntitySet Name="PremiumAccounts" EntityType="kjModel.Store.PremiumAccounts" store:Type="Tables" Schema="dbo" />

    <EntitySet Name="PremiumUsers" EntityType="kjModel.Store.PremiumUsers" store:Type="Tables" Schema="dbo" />

    <EntitySet Name="Users" EntityType="kjModel.Store.Users" store:Type="Tables" Schema="dbo" />

    <AssociationSet Name="FK_Contacts_PremiumUsers" Association="kjModel.Store.FK_Contacts_PremiumUsers">

    <End Role="PremiumUsers" EntitySet="PremiumUsers" />

    <End Role="Contacts" EntitySet="Contacts" />

    </AssociationSet>

    <AssociationSet Name="FK_PremiumAccounts_PremiumUsers" Association="kjModel.Store.FK_PremiumAccounts_PremiumUsers">

    <End Role="PremiumUsers" EntitySet="PremiumUsers" />

    <End Role="PremiumAccounts" EntitySet="PremiumAccounts" />

    </AssociationSet>

    <AssociationSet Name="FK_PremiumUsers_Users" Association="kjModel.Store.FK_PremiumUsers_Users">

    <End Role="Users" EntitySet="Users" />

    <End Role="PremiumUsers" EntitySet="PremiumUsers" />

    </AssociationSet>

    </EntityContainer>

    <EntityType Name="Contacts">

    <Key>

    <PropertyRef Name="ContactId" />

    </Key>

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

    <Property Name="FirstName" Type="nchar" MaxLength="10" />

    <Property Name="SecondName" Type="nchar" MaxLength="10" />

    <Property Name="Email" Type="nchar" MaxLength="10" />

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

    </EntityType>

    <EntityType Name="PremiumAccounts">

    <Key>

    <PropertyRef Name="PremiumUserId" />

    </Key>

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

    <Property Name="ValidFrom" Type="nchar" MaxLength="10" />

    <Property Name="ValidTo" Type="nchar" MaxLength="10" />

    <Property Name="CreatedOn" Type="nchar" MaxLength="10" />

    </EntityType>

    <EntityType Name="PremiumUsers">

    <Key>

    <PropertyRef Name="PremiumUsersId" />

    </Key>

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

    </EntityType>

    <EntityType Name="Users">

    <Key>

    <PropertyRef Name="UserId" />

    </Key>

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

    <Property Name="Email" Type="nchar" MaxLength="10" />

    <Property Name="Password" Type="nchar" MaxLength="10" />

    <Property Name="CreatedOn" Type="nchar" MaxLength="10" />

    </EntityType>

    <Association Name="FK_Contacts_PremiumUsers">

    <End Role="PremiumUsers" Type="kjModel.Store.PremiumUsers" Multiplicity="1" />

    <End Role="Contacts" Type="kjModel.Store.Contacts" Multiplicity="*" />

    <ReferentialConstraint>

    <Principal Role="PremiumUsers">

    <PropertyRef Name="PremiumUsersId" />

    </Principal>

    <Dependent Role="Contacts">

    <PropertyRef Name="PremiumUserId" />

    </Dependent>

    </ReferentialConstraint>

    </Association>

    <Association Name="FK_PremiumAccounts_PremiumUsers">

    <End Role="PremiumUsers" Type="kjModel.Store.PremiumUsers" Multiplicity="1" />

    <End Role="PremiumAccounts" Type="kjModel.Store.PremiumAccounts" Multiplicity="0..1" />

    <ReferentialConstraint>

    <Principal Role="PremiumUsers">

    <PropertyRef Name="PremiumUsersId" />

    </Principal>

    <Dependent Role="PremiumAccounts">

    <PropertyRef Name="PremiumUserId" />

    </Dependent>

    </ReferentialConstraint>

    </Association>

    <Association Name="FK_PremiumUsers_Users">

    <End Role="Users" Type="kjModel.Store.Users" Multiplicity="1" />

    <End Role="PremiumUsers" Type="kjModel.Store.PremiumUsers" Multiplicity="0..1" />

    <ReferentialConstraint>

    <Principal Role="Users">

    <PropertyRef Name="UserId" />

    </Principal>

    <Dependent Role="PremiumUsers">

    <PropertyRef Name="PremiumUsersId" />

    </Dependent>

    </ReferentialConstraint>

    </Association>

    </Schema>

    </edmx:StorageModels>


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, January 11, 2009 8:49 PM

All replies

  • Here you go:

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

    <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">

    <!-- EF Runtime content -->

    <edmx:Runtime>

    <!-- SSDL content -->

    <edmx:StorageModels>

    <Schema Namespace="kjModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">

    <EntityContainer Name="kjModelStoreContainer">

    <EntitySet Name="Contacts" EntityType="kjModel.Store.Contacts" store:Type="Tables" Schema="dbo" />

    <EntitySet Name="PremiumAccounts" EntityType="kjModel.Store.PremiumAccounts" store:Type="Tables" Schema="dbo" />

    <EntitySet Name="PremiumUsers" EntityType="kjModel.Store.PremiumUsers" store:Type="Tables" Schema="dbo" />

    <EntitySet Name="Users" EntityType="kjModel.Store.Users" store:Type="Tables" Schema="dbo" />

    <AssociationSet Name="FK_Contacts_PremiumUsers" Association="kjModel.Store.FK_Contacts_PremiumUsers">

    <End Role="PremiumUsers" EntitySet="PremiumUsers" />

    <End Role="Contacts" EntitySet="Contacts" />

    </AssociationSet>

    <AssociationSet Name="FK_PremiumAccounts_PremiumUsers" Association="kjModel.Store.FK_PremiumAccounts_PremiumUsers">

    <End Role="PremiumUsers" EntitySet="PremiumUsers" />

    <End Role="PremiumAccounts" EntitySet="PremiumAccounts" />

    </AssociationSet>

    <AssociationSet Name="FK_PremiumUsers_Users" Association="kjModel.Store.FK_PremiumUsers_Users">

    <End Role="Users" EntitySet="Users" />

    <End Role="PremiumUsers" EntitySet="PremiumUsers" />

    </AssociationSet>

    </EntityContainer>

    <EntityType Name="Contacts">

    <Key>

    <PropertyRef Name="ContactId" />

    </Key>

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

    <Property Name="FirstName" Type="nchar" MaxLength="10" />

    <Property Name="SecondName" Type="nchar" MaxLength="10" />

    <Property Name="Email" Type="nchar" MaxLength="10" />

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

    </EntityType>

    <EntityType Name="PremiumAccounts">

    <Key>

    <PropertyRef Name="PremiumUserId" />

    </Key>

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

    <Property Name="ValidFrom" Type="nchar" MaxLength="10" />

    <Property Name="ValidTo" Type="nchar" MaxLength="10" />

    <Property Name="CreatedOn" Type="nchar" MaxLength="10" />

    </EntityType>

    <EntityType Name="PremiumUsers">

    <Key>

    <PropertyRef Name="PremiumUsersId" />

    </Key>

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

    </EntityType>

    <EntityType Name="Users">

    <Key>

    <PropertyRef Name="UserId" />

    </Key>

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

    <Property Name="Email" Type="nchar" MaxLength="10" />

    <Property Name="Password" Type="nchar" MaxLength="10" />

    <Property Name="CreatedOn" Type="nchar" MaxLength="10" />

    </EntityType>

    <Association Name="FK_Contacts_PremiumUsers">

    <End Role="PremiumUsers" Type="kjModel.Store.PremiumUsers" Multiplicity="1" />

    <End Role="Contacts" Type="kjModel.Store.Contacts" Multiplicity="*" />

    <ReferentialConstraint>

    <Principal Role="PremiumUsers">

    <PropertyRef Name="PremiumUsersId" />

    </Principal>

    <Dependent Role="Contacts">

    <PropertyRef Name="PremiumUserId" />

    </Dependent>

    </ReferentialConstraint>

    </Association>

    <Association Name="FK_PremiumAccounts_PremiumUsers">

    <End Role="PremiumUsers" Type="kjModel.Store.PremiumUsers" Multiplicity="1" />

    <End Role="PremiumAccounts" Type="kjModel.Store.PremiumAccounts" Multiplicity="0..1" />

    <ReferentialConstraint>

    <Principal Role="PremiumUsers">

    <PropertyRef Name="PremiumUsersId" />

    </Principal>

    <Dependent Role="PremiumAccounts">

    <PropertyRef Name="PremiumUserId" />

    </Dependent>

    </ReferentialConstraint>

    </Association>

    <Association Name="FK_PremiumUsers_Users">

    <End Role="Users" Type="kjModel.Store.Users" Multiplicity="1" />

    <End Role="PremiumUsers" Type="kjModel.Store.PremiumUsers" Multiplicity="0..1" />

    <ReferentialConstraint>

    <Principal Role="Users">

    <PropertyRef Name="UserId" />

    </Principal>

    <Dependent Role="PremiumUsers">

    <PropertyRef Name="PremiumUsersId" />

    </Dependent>

    </ReferentialConstraint>

    </Association>

    </Schema>

    </edmx:StorageModels>


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, January 11, 2009 8:49 PM
  •  

    <!-- CSDL content -->

    <edmx:ConceptualModels>

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

    <EntityContainer Name="kjEntities">

    <EntitySet Name="Contacts" EntityType="kjModel.Contacts" />

    <EntitySet Name="PremiumAccounts" EntityType="kjModel.PremiumAccounts" />

    <EntitySet Name="Users" EntityType="kjModel.Users" />

    <AssociationSet Name="FK_Contacts_PremiumUsers" Association="kjModel.FK_Contacts_PremiumUsers">

    <End Role="PremiumUsers" EntitySet="Users" />

    <End Role="Contacts" EntitySet="Contacts" />

    </AssociationSet>

    <AssociationSet Name="FK_PremiumAccounts_PremiumUsers" Association="kjModel.FK_PremiumAccounts_PremiumUsers">

    <End Role="PremiumUsers" EntitySet="Users" />

    <End Role="PremiumAccounts" EntitySet="PremiumAccounts" />

    </AssociationSet>

    </EntityContainer>

    <EntityType Name="Contacts">

    <Key>

    <PropertyRef Name="ContactId" />

    </Key>

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

    <Property Name="FirstName" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    <Property Name="SecondName" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    <Property Name="Email" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    <NavigationProperty Name="PremiumUsers" Relationship="kjModel.FK_Contacts_PremiumUsers" FromRole="Contacts" ToRole="PremiumUsers" />

    </EntityType>

    <EntityType Name="PremiumAccounts">

    <Key>

    <PropertyRef Name="PremiumUserId" />

    </Key>

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

    <Property Name="ValidFrom" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    <Property Name="ValidTo" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    <Property Name="CreatedOn" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    <NavigationProperty Name="PremiumUsers" Relationship="kjModel.FK_PremiumAccounts_PremiumUsers" FromRole="PremiumAccounts" ToRole="PremiumUsers" />

    </EntityType>

    <EntityType Name="PremiumUsers" BaseType="kjModel.Users">

    <NavigationProperty Name="Contacts" Relationship="kjModel.FK_Contacts_PremiumUsers" FromRole="PremiumUsers" ToRole="Contacts" />

    <NavigationProperty Name="PremiumAccounts" Relationship="kjModel.FK_PremiumAccounts_PremiumUsers" FromRole="PremiumUsers" ToRole="PremiumAccounts" />

    </EntityType>

    <EntityType Name="Users">

    <Key>

    <PropertyRef Name="UserId" />

    </Key>

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

    <Property Name="Email" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    <Property Name="Password" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    <Property Name="CreatedOn" Type="String" MaxLength="10" Unicode="true" FixedLength="true" />

    </EntityType>

    <Association Name="FK_Contacts_PremiumUsers">

    <End Role="PremiumUsers" Type="kjModel.PremiumUsers" Multiplicity="1" />

    <End Role="Contacts" Type="kjModel.Contacts" Multiplicity="*" />

    </Association>

    <Association Name="FK_PremiumAccounts_PremiumUsers">

    <End Role="PremiumUsers" Type="kjModel.PremiumUsers" Multiplicity="1" />

    <End Role="PremiumAccounts" Type="kjModel.PremiumAccounts" Multiplicity="0..1" />

    <ReferentialConstraint>

    <Principal Role="PremiumUsers">

    <PropertyRef Name="UserId" />

    </Principal>

    <Dependent Role="PremiumAccounts">

    <PropertyRef Name="PremiumUserId" />

    </Dependent>

    </ReferentialConstraint>

    </Association>

    </Schema>

    </edmx:ConceptualModels>


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, January 11, 2009 8:50 PM
  •  

    <!-- C-S mapping content -->

    <edmx:Mappings>

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

    <EntityContainerMapping StorageEntityContainer="kjModelStoreContainer" CdmEntityContainer="kjEntities">

    <EntitySetMapping Name="Contacts">

    <EntityTypeMapping TypeName="IsTypeOf(kjModel.Contacts)">

    <MappingFragment StoreEntitySet="Contacts">

    <ScalarProperty Name="ContactId" ColumnName="ContactId" />

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

    <ScalarProperty Name="SecondName" ColumnName="SecondName" />

    <ScalarProperty Name="Email" ColumnName="Email" />

    </MappingFragment>

    </EntityTypeMapping>

    </EntitySetMapping>

    <EntitySetMapping Name="PremiumAccounts">

    <EntityTypeMapping TypeName="IsTypeOf(kjModel.PremiumAccounts)">

    <MappingFragment StoreEntitySet="PremiumAccounts">

    <ScalarProperty Name="PremiumUserId" ColumnName="PremiumUserId" />

    <ScalarProperty Name="ValidFrom" ColumnName="ValidFrom" />

    <ScalarProperty Name="ValidTo" ColumnName="ValidTo" />

    <ScalarProperty Name="CreatedOn" ColumnName="CreatedOn" />

    </MappingFragment>

    </EntityTypeMapping>

    </EntitySetMapping>

    <EntitySetMapping Name="Users">

    <EntityTypeMapping TypeName="IsTypeOf(kjModel.Users)">

    <MappingFragment StoreEntitySet="Users">

    <ScalarProperty Name="UserId" ColumnName="UserId" />

    <ScalarProperty Name="Email" ColumnName="Email" />

    <ScalarProperty Name="Password" ColumnName="Password" />

    <ScalarProperty Name="CreatedOn" ColumnName="CreatedOn" />

    </MappingFragment>

    </EntityTypeMapping>

    <EntityTypeMapping TypeName="IsTypeOf(kjModel.PremiumUsers)">

    <MappingFragment StoreEntitySet="PremiumUsers">

    <ScalarProperty Name="UserId" ColumnName="PremiumUsersId" />

    </MappingFragment>

    </EntityTypeMapping>

    </EntitySetMapping>

    <AssociationSetMapping Name="FK_Contacts_PremiumUsers" TypeName="kjModel.FK_Contacts_PremiumUsers" StoreEntitySet="Contacts">

    <EndProperty Name="PremiumUsers">

    <ScalarProperty Name="UserId" ColumnName="PremiumUserId" />

    </EndProperty>

    <EndProperty Name="Contacts">

    <ScalarProperty Name="ContactId" ColumnName="ContactId" />

    </EndProperty>

    </AssociationSetMapping>

    <AssociationSetMapping Name="FK_PremiumAccounts_PremiumUsers" TypeName="kjModel.FK_PremiumAccounts_PremiumUsers" StoreEntitySet="PremiumAccounts">

    <EndProperty Name="PremiumUsers">

    <ScalarProperty Name="UserId" ColumnName="PremiumUserId" />

    </EndProperty>

    <EndProperty Name="PremiumAccounts">

    <ScalarProperty Name="PremiumUserId" ColumnName="PremiumUserId" />

    </EndProperty>

    </AssociationSetMapping>

    </EntityContainerMapping>

    </Mapping>

    </edmx:Mappings>

    </edmx:Runtime>

    <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->

    <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">

    <edmx:Connection>

    <DesignerInfoPropertySet>

    <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />

    </DesignerInfoPropertySet>

    </edmx:Connection>

    <edmx:Options>

    <DesignerInfoPropertySet>

    <DesignerProperty Name="ValidateOnBuild" Value="true" />

    </DesignerInfoPropertySet>

    </edmx:Options>

    <!-- Diagram content (shape and connector positions) -->

    <edmx:Diagrams>

    <Diagram Name="Model1">

    <EntityTypeShape EntityType="kjModel.Contacts" Width="1.5" PointX="5.25" PointY="1" Height="1.7566536458333335" IsExpanded="true" />

    <EntityTypeShape EntityType="kjModel.PremiumAccounts" Width="1.5" PointX="5.25" PointY="3.5" Height="1.7566536458333335" IsExpanded="true" />

    <EntityTypeShape EntityType="kjModel.PremiumUsers" Width="1.5" PointX="2.375" PointY="3.125" Height="1.2636116536458326" IsExpanded="true" />

    <EntityTypeShape EntityType="kjModel.Users" Width="1.5" PointX="0.75" PointY="0.75" Height="1.592306315104167" IsExpanded="true" />

    <AssociationConnector Association="kjModel.FK_Contacts_PremiumUsers" ManuallyRouted="false">

    <ConnectorPoint PointX="3.125" PointY="3.125" />

    <ConnectorPoint PointX="3.125" PointY="1.8783268229166668" />

    <ConnectorPoint PointX="5.25" PointY="1.8783268229166668" />

    </AssociationConnector>

    <AssociationConnector Association="kjModel.FK_PremiumAccounts_PremiumUsers" ManuallyRouted="false">

    <ConnectorPoint PointX="3.875" PointY="3.9443058268229163" />

    <ConnectorPoint PointX="5.25" PointY="3.9443058268229163" />

    </AssociationConnector>

    <InheritanceConnector EntityType="kjModel.PremiumUsers">

    <ConnectorPoint PointX="1.5" PointY="2.342306315104167" />

    <ConnectorPoint PointX="1.5" PointY="3.7568058268229163" />

    <ConnectorPoint PointX="2.375" PointY="3.7568058268229163" />

    </InheritanceConnector>

    </Diagram>

    </edmx:Diagrams>

    </edmx:Designer>

    </edmx:Edmx>


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, January 11, 2009 8:50 PM