CodeSmith Community
Your Code. Your Way. Faster!

Many-to-Many Relationship using Web Library Controls

Latest post 07-20-2006 1:59 PM by Alex. 10 replies.
  • 04-12-2006 12:47 PM

    • bdiaz
    • Top 10 Contributor
    • Joined on 02-20-2006
    • Houston, TX
    • Posts 504
    • Points 15,290

    Many-to-Many Relationship using Web Library Controls

    The ManyToManyListRelationship control manages the junction table that links your primary entity with a foreign key table.

    <asp:FormView ID="FormView1" runat="server" DataSourceID="CustomersDataSource" DefaultMode="Edit">
        <EditItemTemplate>
            <table border="0">
            <tr>
                <td>Cust #:</td>
                <td><asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Bind("CustomerID") %>' /></td>
            </tr>
            <tr>
                <td>Company Name:</td>
                <td><asp:TextBox ID="CompanyNameTextBox" runat="server" Text='<%# Bind("CompanyName") %>' /></td>
            </tr>
            <tr>
                <td valign="top">Demographics:</td>
                <td>
                    <!-- the visual representation of the many-to-many relationship -->
                    <asp:CheckBoxList ID="CustomerDemographicsList" runat="server"
                        DataSourceID="CustomerDemographicsDataSource"
                        DataTextField="CustomerDesc"
                        DataValueField="CustomerTypeID"
                    />
                    
                    <!-- provides the list of available data for the relationship -->
                    <data:EntityDataSource ID="CustomerDemographicsDataSource" runat="server"
                        ProviderName="CustomerDemographicsProvider"
                        EntityTypeName="Northwind.BLL.CustomerDemographics, Northwind.BLL"
                        SelectMethod="GetAll"
                        Filter="CustomerDesc != 'Temporary'"
                        Sort="CustomerDesc ASC"
                    />
                    
                    <!-- provides management of the link table -->
                    <data:EntityDataSource ID="CustomerCustomerDemoDataSource" runat="server"
                        ProviderName="CustomerCustomerDemoProvider"
                        EntityTypeName="Northwind.BLL.CustomerCustomerDemo, Northwind.BLL"
                        EntityKeyTypeName="System.String"
                        SelectMethod="GetByCustomerID"
                    >
                        <Parameters>
                            <asp:QueryStringParameter Name="EntityId" QueryStringField="id" />
                        </Parameters>
                    </data:EntityDataSource>
                    
                    <!--
                        The relationship controls hook one or more EntityDataSource controls to the
                        EntityDataSource specified by the PrimaryMember.EntityDataSourceID property.
                        This allows multiple insert/update operations to be executed during a single
                        form submission.
                    -->

                    <data:ManyToManyListRelationship ID="CustomerCustomerDemoRelationship" runat="server">
                        <%-- represents the Customers table --%>
                        <PrimaryMember runat="server"
                            DataSourceID="CustomersDataSource"
                            EntityKeyName="CustomerID"
                        />

                        <%-- represents the CustomerCustomerDemo link table --%>
                        <LinkMember runat="server"
                            DataSourceID="CustomerCustomerDemoDataSource"
                            EntityKeyName="CustomerID"
                            ForeignKeyName="CustomerTypeID"
                        />

                        <%-- represents the CustomerDemographics table --%>
                        <ReferenceMember runat="server"
                            DataSourceID="CustomerDemographicsDataSource"
                            ListControlID="CustomerDemographicsList"
                            EntityKeyName="CustomerTypeID"
                        />
                    </data:ManyToManyListRelationship>

                </td>
            </tr>
            </table>
        </EditItemTemplate>
        
        <FooterTemplate>
            <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
            <asp:Button ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </FooterTemplate>
    </asp:FormView>

    <!-- primary entity data source -->
    <data:EntityDataSource ID="CustomersDataSource" runat="server"
        ProviderName="CustomersProvider"
        EntityTypeName="Northwind.BLL.Customers, Northwind.BLL"
        EntityKeyTypeName="System.String"
        EntityKeyName="CustomerID"
        SelectMethod="GetByCustomerID"
    >
        <Parameters>
            <asp:QueryStringParameter Name="EntityId" QueryStringField="id" Type="String" />
        </Parameters>
    </data:EntityDataSource>


    Bobby Diaz ------------------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------------------
    • Post Points: 105
  • 04-12-2006 1:08 PM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    Re: Many-to-Many Relationship using Web Library Controls

    A screen shot would be cool.

    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 35
  • 04-12-2006 2:10 PM In reply to

    • bdiaz
    • Top 10 Contributor
    • Joined on 02-20-2006
    • Houston, TX
    • Posts 504
    • Points 15,290

    Re: Many-to-Many Relationship using Web Library Controls

    Here is the screenshot for the example code above.  The cool thing is that it works as-is with nothing in the code-behind!

    Thanks,
    Bobby


    Bobby Diaz ------------------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------------------
    • Post Points: 5
  • 04-16-2006 10:08 AM In reply to

    • funky81
    • Top 500 Contributor
    • Joined on 04-15-2006
    • Posts 13
    • Points 335

    Re: Many-to-Many Relationship using Web Library Controls

    any others documentation beside this one?
    • Post Points: 35
  • 04-17-2006 11:38 PM In reply to

    • bdiaz
    • Top 10 Contributor
    • Joined on 02-20-2006
    • Houston, TX
    • Posts 504
    • Points 15,290

    Re: Many-to-Many Relationship using Web Library Controls

    Here is the link to the .netTiers Documentation forum, which is where I am putting the documentation and sample code for the Web Library:

    http://community.codesmithtools.com/forums/33/ShowForum.aspx


    Thanks,
    Bobby


    Bobby Diaz ------------------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------------------
    • Post Points: 35
  • 04-21-2006 10:46 AM In reply to

    • guli
    • Top 500 Contributor
    • Joined on 12-29-2005
    • Posts 17
    • Points 480

    Re: Many-to-Many Relationship using Web Library Controls

    Bobby,

    Thank you for the excellent work with the web library.

    I have two questions

    1. My junction table contains audit columns such as createdBy, which should contain the username of the person that added the record. Which event, on which object, should I hook into to set that.

    2.  Can I use the ManyToMany controls if I have an even more complicated junction table, say with three foreign keys. (And yes, the PK is a composite of all the FKs). For example, in my db I store addresses in a separate table. Addresses can be connected to many different objects such as companies, persons, offices and so on.

    Example PK tables :
    Person(personId, ....) 
    Address(addressId, ...)
    AddressType(addressTypeId, Typename) (home, mailing, visiting...)

    Junction Table:
    PersonAddress(personid, addressId, addressTypeId, ....audit columns )

    Any help appreciated.

    Thanks,

     Gustaf

     

     

     

    • Post Points: 60
  • 04-21-2006 5:47 PM In reply to

    • bdiaz
    • Top 10 Contributor
    • Joined on 02-20-2006
    • Houston, TX
    • Posts 504
    • Points 15,290

    Re: Many-to-Many Relationship using Web Library Controls

    Gustaf,

    I am currently working on a project that has an almost identical data model to the one you are describing as well as the same auditing requirements.  I will post an example in the documentation thread as soon as I can put it together!

    Thanks,
    Bobby

    Bobby Diaz ------------------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------------------
    • Post Points: 35
  • 04-22-2006 1:37 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Many-to-Many Relationship using Web Library Controls

    Bobby,

    I would be interested to see your example too.

    Thanks a lot!

    Michael

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 5
  • 04-23-2006 11:11 PM In reply to

    • bdiaz
    • Top 10 Contributor
    • Joined on 02-20-2006
    • Houston, TX
    • Posts 504
    • Points 15,290

    Re: Many-to-Many Relationship using Web Library Controls

    Gustaf,

    Take a look at the new documentation thread I just posted that shows how to handle this type of scenario.

    http://community.codesmithtools.com/forums/thread/12874.aspx

    Thanks,
    Bobby


    Bobby Diaz ------------------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------------------
    • Post Points: 35
  • 04-24-2006 1:41 AM In reply to

    • guli
    • Top 500 Contributor
    • Joined on 12-29-2005
    • Posts 17
    • Points 480

    Re: Many-to-Many Relationship using Web Library Controls

    Bobby

    This is so cool. Will try this asap.. Thanks alot

    Gustaf

    • Post Points: 5
  • 07-20-2006 1:59 PM In reply to

    • Alex
    • Top 10 Contributor
    • Joined on 07-26-2005
    • Australia, Canberra
    • Posts 526
    • Points 10,645

    Re: Many-to-Many Relationship using Web Library Controls

    Bobby, this is cool, but too I don't understand how this work... Can you explain more idea about ManyToMany control? Thanks.
    Best regards,
    Alex.
    • Post Points: 5
Page 1 of 1 (11 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems