views:

15

answers:

0

Hi.

Iam using LinqToSql togheter with an XmlMappingFile so a can use POCO. I have an entity that is called Address. And in this Entity I have entity called Country. This entity is populated from database, but that table should never be changed since it has a list of all countries and is "Hardcoded".

I have a Club entity that has a list of Addresses entities, and when I add an Club to database the addresses are also saved to the databas, but then it tries to insert my country entity also, and it will then failed with the "Cannot add an entity with a key that is already in use"

My XmlMappingFile looks like this.

  <Table Name="dbo.Address" Member="Address">
    <Type Name="TS.Club.Domain.Model.ValueObject.Address">
      <Column Name="Identifier" Member="Identifier" DbType="UniqueIdentifier NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="false" AutoSync="OnInsert" />
      <Column Name="ReferenceIdentifier" Member="ReferenceIdentifier" DbType="UniqueIdentifier NOT NULL"/>
      <Column Name="CountryIdentifier" Member="CountryIdentifier" DbType="UniqueIdentifier NOT NULL"/>
      <Column Name="StreetAddress" Member="StreetAddress" DbType="Varchar(512)"/>
      <Column Name="ZipCode" Member="ZipCode" DbType="Varchar(8)"/>
      <Column Name="City" Member="City" DbType="Varchar(512)"/>
      <Column Name="AddressType" Member="Type" DbType="tinyint"/>
      <Association Member="Country" ThisKey="CountryIdentifier" IsForeignKey="true" DeleteRule="NO ACTION" />
    </Type>
  </Table>
  <Table Name="dbo.Club" Member="Club">
    <Type Name="TS.Club.Domain.Model.Club">
      <Column Name="Identifier" Member="Identifier" DbType="UniqueIdentifier NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="false" AutoSync="OnInsert" />
      <Column Name="Name" Member="Name" DbType="Varchar(512)" />
      <Column Name="Email" Member="Email" DbType="Varchar(512)" />
      <Column Name="Bankgiro" Member="Bankgiro" DbType="Varchar(16)"/>
      <Column Name="Postgiro" Member="Postgiro" DbType="Varchar(16)"/>
      <Column Name="Information" Member="Information" DbType="Text" UpdateCheck="Never"/>
      <Column Name="CreatedOn" Member="CreatedOn" DbType="DateTime2"/>
      <Column Name="UpdatedOn" Member="UpdateOn" DbType="DateTime2"/>
      <Column Name="SecretariatOpeninghours" Member="SecretariatOpeninghours" DbType="Varchar(512)"/>
      <Association Member="Phonenumbers" ThisKey="Identifier" OtherKey="ReferenceIdentifier" DeleteRule="NO ACTION" />
      <Association Member="Addresses" ThisKey="Identifier" OtherKey="ReferenceIdentifier" DeleteRule="NO ACTION" />
    </Type>
  </Table>
  <Table Name="dbo.sysCountry" Member="Country">
    <Type Name="TS.Club.Domain.Model.ValueObject.Country">
      <Column Name="Identifier" Member="Identifier" DbType="UniqueIdentifier NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="false" AutoSync="OnInsert" />
      <Column Name="Name" Member="Name" DbType="Varchar(512)" />
    </Type>
  </Table>

Is there some way to specified in the xmlfile that I don't want to do anything but read in my sysCountry table, the intellisens dosen't help me.

Thanks Magnus