CodeSmith Community
Your Code. Your Way. Faster!

Working with multiple datasources - please help!

Latest post 04-11-2007 5:47 PM by basolutions. 10 replies.
  • 04-06-2007 1:40 PM

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Working with multiple datasources - please help!

    All,

    I have a web page that I need to display information from three different tables:  Account, Customer, and User.  The only data that is editable it the Customer information, but me requirements state that I need to show information from the Account and User tables.  If I try to put the three datasources on the the webform without a relationship control, it doesn't work, so I suspect that I will need to use a combination of the relationship controls to connect the three tables together.  I just don't how and I can't seem to find much documentation for the relationship objects.

    More details:  The page recieves a querystring variable called UserId which is the primary key of the User table and is a foreign key in the Contact table.  The Contact table also has a foriegn key back to the Account table.

    Can anyone please show me how to make this work or have a similar example?  I have looked at the documentation for the many to many control, but I can't seem to get my mind around how I can apply that example to my needs.

     Thanks,

     Jesse

    • Post Points: 35
  • 04-06-2007 11:20 PM In reply to

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

    Re: Working with multiple datasources - please help!

    Jesse,

    See if this helps http://community.codesmithtools.com/forums/permalink/22688/22702/ShowThread.aspx#22702

    The configuration file would look like this: 

    <Configuration><Modules><Module Name="Edit Company" ParentEntity="User" QueryStringParameterName="UserId" Overwrite="true">

    <IncludeEntities>

      <Entity Name="Company" />

      <Entity Name="Address" />

    </IncludeEntities>

     </Module>

     </Modules>

     </Configuration>

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

    • Post Points: 45
  • 04-09-2007 9:54 AM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: Working with multiple datasources - please help!

    Mike,

    Thanks for the help on this issue.  I read the previous thread and it seems pretty straight forward, except I am looking at the netTiers properties that I can set in CodeSmith for the config file, but I dont't see any property called Module Config->ConfigFile.  Am I missing something?  The closest thing that I see to it is the MappingFile property, but I don't think that is right.

    Thanks,

    Jesse

    • Post Points: 35
  • 04-09-2007 10:11 AM In reply to

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

    Re: Working with multiple datasources - please help!

    Jesse,

    This template isn't integrated  into the main set, and probably won't be, as it doesn't support 100% of all cases. The idea is to help get started with a configuration of  ui relationship controls.

     

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

    • Post Points: 35
  • 04-09-2007 10:29 AM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: Working with multiple datasources - please help!

    Mike,

    Thanks for the response.  I think I just got a little confused about how it was supposed to work.  I downloaded the zip and I got it configured.  Is there a specific location that this cst and config file need to be placed within the netTiers template folder structure?  I put the files one level above the topmost netTiers source folder and modified the cst to point to \Source\Source\TemplateLib\CommonSqlCode.cs, but I am getting an error - Could not Find: ////Mappings//Class/Contacts xpath. 

    I am guessing that I need to put this cst in a specific location so that it can find other mapping files?

     Thanks so much for your time and help.

    • Post Points: 35
  • 04-09-2007 11:20 AM In reply to

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

    Re: Working with multiple datasources - please help!

    Jesse,

    Could not Find: ////Mappings//Class/Contacts xpath. Where Contacts is your business entity name, you may need to strip the prefix via StrippedTablePrefixes attribute. Is it the case?

     


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

    • Post Points: 35
  • 04-10-2007 1:22 PM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: Working with multiple datasources - please help!

    Mike,

     After reviewing my settings, it turned out that I had an error in my xml file.  I got your template to work, but it didn't seem to help me understand the relationship issue any better.  I was able to find some other threads that cover ManyToMany as well as OnetoOne relationships and that got me a lot further.  I will try to document what I have learned and add it to the nettiers documentation.  Hopefully this will help others as well.  It will probably take me a week or so to put the documentation together.

     Thanks for your help,

    Jesse

    • Post Points: 5
  • 04-11-2007 1:54 PM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: Working with multiple datasources - please help!

    I am still lost on the relationship controls.  Can anyone tell me why this doesn't work?  I have no problem updating the contact information, but for whatever reason I can't get the membership user table to update.  I'm hoping someone can point me in the right direction.

    Tables:
    Contacts (MxlContactId PK, UserFk FK)
    aspnet_Membership (UserId PK)

    Thanks,

    Jesse

     

    <asp:FormView ID="ContactView" runat="server" DataKeyNames="MxlContactId" DataSourceID="ContactsDataSource1"
    DefaultMode="edit" Width="100%">
    <EditItemTemplate>
    <table border="0" cellpadding="2" cellspacing="2" width="100%">
    <tr align="left" valign="top">
    <td nowrap="nowrap">
    <asp:Label ID="lblFirstName" runat="server" Text="*First Name:"></asp:Label></td>
    <td nowrap="nowrap">
    <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'>
    </asp:TextBox></td>
    </tr>
    </table>

    <asp:FormView ID="MembershipView" runat="server" DataKeyNames="UserId" DataSourceID="AspnetMembershipDataSource1"
    Width="100%">
    <ItemTemplate>
    <table border="0" cellpadding="2" cellspacing="2" width="100%">
    <tr>
    <td>
    <asp:Label ID="lblUserStatus" runat="server" Text="*User Status:"></asp:Label>
    </td>
    <td class="ReqField">
    </td>
    <td>
    <asp:CheckBox ID="chkUserStatus" runat="server" Checked='<%# Bind("IsApproved") %>'
    Enabled="true" />
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:FormView>

    </EditItemTemplate>

    <HeaderTemplate>
    <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
    Text="Update" />
    </HeaderTemplate>
    </asp:FormView>

    <data:ContactsDataSource ID="ContactsDataSource1" runat="server" SelectMethod="getbyuserfk"
    UpdateMethod="Save">
    <Parameters>
    <asp:QueryStringParameter Name="userFk" QueryStringField="UserId" />
    </Parameters>
    </data:ContactsDataSource>

    <data:Aspnet_MembershipDataSource ID="AspnetMembershipDataSource1" runat="server"
    SelectMethod="GetByUserId">
    <Parameters>
    <asp:QueryStringParameter Name="userId" QueryStringField="UserId" />
    </Parameters>
    </data:Aspnet_MembershipDataSource>

    <data:OneToOneViewRelationship ID="ContactMembershipRelationship" runat="server">
    <PrimaryMember ID="PrimaryMember2" runat="server" DataSourceID="ContactsDataSource1"
    ViewControlID="ContactView" >
    </PrimaryMember>
    <ReferenceMember ID="ReferenceMember2" runat="Server" DataSourceID="AspnetMembershipDataSource1"
    ViewControlID="MembershipView" >
    </ReferenceMember>
    </data:OneToOneViewRelationship>

    • Post Points: 65
  • 04-11-2007 4:00 PM In reply to

    • mduray
    • Top 150 Contributor
    • Joined on 03-15-2007
    • Posts 27
    • Points 525

    Re: Working with multiple datasources - please help!

    Please forgive me if I'm missing something, but why wouldn't you only deal with one datasource and deep load / deep save?  Wouldn't that work?
    • Post Points: 5
  • 04-11-2007 5:26 PM In reply to

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

    Re: Working with multiple datasources - please help!

    Jesse,

    Try setting EntityKeyNames like following (also be aware the keys are case-sensitive):

    <data:OneToOneViewRelationship ID="ContactMembershipRelationship" runat="server">
            <PrimaryMember ID="PrimaryMember2" runat="server"
                    DataSourceID="ContactsDataSource1"
                    ViewControlID="ContactView"
                    EntityKeyName="MxlContactId"
                >
            </PrimaryMember>
        <ReferenceMember ID="ReferenceMember2" runat="Server"
                    DataSourceID="AspnetMembershipDataSource1"
                    ViewControlID="MembershipView"
                    EntityKeyName="UserId"
                >
            </ReferenceMember>
    </data:OneToOneViewRelationship> 

    basolutions:

    ....

    <data:OneToOneViewRelationship ID="ContactMembershipRelationship" runat="server">
    <PrimaryMember ID="PrimaryMember2" runat="server" DataSourceID="ContactsDataSource1"
    ViewControlID="ContactView" >
    </PrimaryMember>
    <ReferenceMember ID="ReferenceMember2" runat="Server" DataSourceID="AspnetMembershipDataSource1"
    ViewControlID="MembershipView" >
    </ReferenceMember>
    </data:OneToOneViewRelationship>

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

    • Post Points: 5
  • 04-11-2007 5:47 PM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: Working with multiple datasources - please help!

    First, I want to thank everyone that has taken the time to help me figure this problem out.  Unfortunately, there isn't a lot of documentation to go on for the relationship controls and how to properly use them, which makes this tough.  I finally figured out what the problem was.  First, this example I provided is a very simple version of what I am trying to load, so I don't think that deep loading is the right answer, but maybe its another way to approach the problem.  Second, the Entity keys didn't make a difference, and I looked at a couple of examples that didn't use them either.

    Anyway, the solution:

    One, I had to move my OnetoOneViewRelationship from the bottom of the page to inside of the <EditItemTemplate> of the ContactView FormView.  If it's not inside of the outermost formview, the records don't get updated.  I also had to change <ItemTemplate> to <EditItemTemplate> on my inner formview, MembershipView, as well as set it's DefaultMode="edit".  Once I made these changes, it worked.  My updated source is below.

    Can anyone tell me when I should be using a FormView vs. MultiFormView?

    So, I will work on some documentation for what I have found and add it to the wiki.  Hopefully it will help someone else.


    <asp:FormView ID="ContactView" runat="server" DataKeyNames="MxlContactId" DataSourceID="ContactsDataSource1"
    DefaultMode="edit" Width="100%">
    <EditItemTemplate>
    <table border="0" cellpadding="2" cellspacing="2" width="100%">
    <tr align="left" valign="top">
    <td nowrap="nowrap">
    <asp:Label ID="lblFirstName" runat="server" Text="*First Name:"></asp:Label></td>
    <td nowrap="nowrap">
    <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'>
    </asp:TextBox></td>
    </tr>
    </table>

    <asp:FormView ID="MembershipView" runat="server" DataKeyNames="UserId" DataSourceID="AspnetMembershipDataSource1"
    Width="100%" DefaultMode="edit">
    <EditItemTemplate>
    <table border="0" cellpadding="2" cellspacing="2" width="100%">
    <tr>
    <td>
    <asp:Label ID="lblUserStatus" runat="server" Text="*User Status:"></asp:Label>
    </td>
    <td class="ReqField">
    </td>
    <td>
    <asp:CheckBox ID="chkUserStatus" runat="server" Checked='<%# Bind("IsApproved") %>'
    Enabled="true" />
    </td>
    </tr>
    </table>
    </EditItemTemplate>
    </asp:FormView>

    <data:OneToOneViewRelationship ID="ContactMembershipRelationship" runat="server">
    <PrimaryMember ID="PrimaryMember2" runat="server" DataSourceID="ContactsDataSource1"
    ViewControlID="ContactView">
    </PrimaryMember>
    <ReferenceMember ID="ReferenceMember2" runat="Server" DataSourceID="AspnetMembershipDataSource1"
    ViewControlID="MembershipView">
    </ReferenceMember>
    </data:OneToOneViewRelationship>

    </EditItemTemplate>

    <HeaderTemplate>
    <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
    Text="Update" />
    </HeaderTemplate>

    </asp:FormView>

    <data:ContactsDataSource ID="ContactsDataSource1" runat="server" SelectMethod="getbyuserfk"
    UpdateMethod="Save">
    <Parameters>
    <asp:QueryStringParameter Name="userFk" QueryStringField="UserId" />
    </Parameters>
    </data:ContactsDataSource>

    <data:Aspnet_MembershipDataSource ID="AspnetMembershipDataSource1" runat="server"
    SelectMethod="GetByUserId">
    <Parameters>
    <asp:QueryStringParameter Name="userId" QueryStringField="UserId" />
    </Parameters>
    </data:Aspnet_MembershipDataSource>

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