CodeSmith Community
Your Code. Your Way. Faster!

Many to Many issue when both entity tables have the same name for the primary key field

Latest post 05-09-2007 5:35 PM by smallinov. 1 replies.
  • 05-09-2007 3:42 PM

    • millerwa
    • Top 500 Contributor
    • Joined on 05-03-2007
    • Posts 18
    • Points 465

    Many to Many issue when both entity tables have the same name for the primary key field

    The code generated for the many to many relationship I think is getting confused when two Entity Tables both have the same column name for the primary key.

    Table structure.

    Dealer

    ---------

    PKID int

    Name varchar(100)

    Address1 varchar(150)

    ....

    Country

    ----------

    PKID int

    Name varchar(150)

    Code char(4)

     

    DealerCountry

    -----------------

    DealerID

    CountryID

    This table has foriegn keys

    DealerID --> Dealer.PKID

    CountryID --> Country.PKID

    Now when wanting to edit a Dealer, I should be able to also assign countries to that dealer. However the code generated does is not properly setting some of the attributes properly.

    The issue is that when on the selecting a dealer the querystring has something like .../Admin/DealerEdit.aspx?PKID=174690 which brings up the dealer, but the fails to propely show the related countries associated with the dealer.

    If a country is selected the error of something like "Cannot add PKID to dictionary as it already exists"

    So looking at the code generated there are some items that are not correctly set.

    Once fixed the page works fine.

    Original code generated:

    <asp:CheckBoxList ID="CountryList" runat="server" DataSourceID="CountryDataSource" DataTextField="Name" DataValueField="PKID" RepeatColumns="4" />

    <data:CountryDataSource ID="CountryDataSource" runat="server" SelectMethod="GetAll" />

    <data:DealerCountryDataSource ID="DealerCountryDataSource" runat="server" SelectMethod="GetByCountryID">

    <Parameters>

    <asp:QueryStringParameter Name="CountryID" QueryStringField="PKID" Type="String" />

    </Parameters>

    </data:DealerCountryDataSource>

     

    <data:ManyToManyListRelationship ID="DealerCountryRelationship" runat="server">

    <PrimaryMember runat="server" DataSourceID="DealerDataSource" EntityKeyName="PKID" />

    <LinkMember runat="server" DataSourceID="DealerCountryDataSource" EntityKeyName="CountryID" ForeignKeyName="CountryID" />

    <ReferenceMember runat="server" DataSourceID="CountryDataSource" ListControlID="CountryList" EntityKeyName="PKID"/>

    </data:ManyToManyListRelationship>

    It should be:

    <asp:CheckBoxList ID="CountryList" runat="server" DataSourceID="CountryDataSource" DataTextField="Name" DataValueField="PKID" RepeatColumns="4"/>

    <data:CountryDataSource ID="CountryDataSource" runat="server" SelectMethod="GetAll" />

    <data:DealerCountryDataSource ID="DealerCountryDataSource" runat="server" SelectMethod="GetByDealerID">

    <Parameters>

    <asp:QueryStringParameter Name="DealerID" QueryStringField="PKID" Type="String" />

    </Parameters>

    </data:DealerCountryDataSource>

    <data:ManyToManyListRelationship ID="DealerCountryRelationship" runat="server">

    <PrimaryMember ID="PrimaryMember1" runat="server" DataSourceID="DealerDataSource" EntityKeyName="PKID" />

    <LinkMember ID="LinkMember1" runat="server" DataSourceID="DealerCountryDataSource" EntityKeyName="DealerID" ForeignKeyName="CountryID" />

    <ReferenceMember ID="ReferenceMember1" runat="server" DataSourceID="CountryDataSource" ListControlID="CountryList" EntityKeyName="PKID"/>

    </data:ManyToManyListRelationship>

    Is this a bug, or is there something else I missed.

    I tested this further and if the tables do not have use the same field name the code generates correctly.

    • Post Points: 35
  • 05-09-2007 5:35 PM In reply to

    Re: Many to Many issue when both entity tables have the same name for the primary key field

    Can an admin move this to the .netTiers forum?

    Thanks,

    Ryan

    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems