Welcome to the CodeSmith Community!

EntityDataSource woes

.netTiers

A description has not yet been added to this group.

EntityDataSource woes

  • rated by 0 users
  • This post has 11 Replies |
  • 4 Followers
  • Hi guys,

    I fear that I am at wit's end trying to use the multiFormView control and the EntityDataSource. I have followed all examples I can find, reviewing all code word for word, but can not fix the following issue:

    It keeps on inserting empty values in the database. Has anyone had any issues with this?

    I see that in all your examples, you are using an EntityDataSource to insert,update and delete, but the only parameters being specified are those for the QueryStringParameter.

    Anyone's help or input would be greatly appreciated.

    Thanks very much,

    James
  • Hi, please post the code you're trying to use.


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------

  • Hi Robert,

    Thanks for the quick reply. Here is the code that I am using:

    <data:MultiFormView ID="mfvCareer" runat="server" DataSourceID="_CareerDataSource">
                <EditItemTemplatePaths>
                    <data:TemplatePath Path="/Controls/CareerFields.ascx" />
                </EditItemTemplatePaths>
           
                <InsertItemTemplatePaths>
                    <data:TemplatePath Path="/Controls/CareerFields.ascx" />
                </InsertItemTemplatePaths>
           
                <EmptyDataTemplate>
                    <b>Customer not found!</b>
                </EmptyDataTemplate>
               
                <FooterTemplate>
                    <asp:Button ID="btnInsert" runat="server" CausesValidation="true" CommandName="Insert" Text="Insert" />
                    <asp:Button ID="btnUpdate" runat="server" CausesValidation="true" CommandName="Update" Text="Update" />
                    <asp:Button ID="btnCancel" runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel" />
                    <asp:Button id="btnNew" runat="server" CausesValidation="false" CommandName="New" Text="Add New" />
                </FooterTemplate>
               
            </data:MultiFormView>
           
            <data:EntityDataSource ID="_CareerDataSource" runat="server"
                ProviderName="_CareerProvider"
                EntityTypeName="TestFrameworkHeadToHead.Entities._Career, TestFrameworkHeadToHead.Entities"
                EntityKeyTypeName="System.Int32"
                EntityKeyName="ID"
                SelectMethod="GetById">
                <Parameters>
                    <asp:QueryStringParameter Name="EntityId" QueryStringField="ID" />
                </Parameters>           
            </data:EntityDataSource>

    The table name is tbl_Career, so the generated names are _Career. Using this code if I try to insert a career it inserts empty values, and if I pass through a querystring value with the ID to use in order to edit a record, it says that it can't find the record in question.

    The path to the user control is correct.

    Any suggestions? I am using the 2.0.0.0 beta 2 release. I generated the code using the "UseWebAppProject" value set to true. Any other settings that may have an effect?

    Thanks,

    James
  • Stepping through the code, the problem seems to lie in this method in the EntityUtil class. The GetById method is not getting returned:

            public static MethodInfo GetMethod(Type type, String methodName, Type[] types)
            {
                MethodInfo m = null;

                if ( type != null && !String.IsNullOrEmpty(methodName) )
                {
                    m = type.GetMethod(methodName, (types ?? Type.EmptyTypes));
                }

                return m;
            }

    Values at run time:
    - type = {Name = "Sql_CareerProvider" FullName = "TestFrameworkHeadToHead.Data.SqlClient.Sql_CareerProvider"}
    - methodName = "GetById"
    - types[0] = {Name = "TransactionManager" FullName = "TestFrameworkHeadToHead.Data.TransactionManager"}
    - types[1] = {Name = "Int32" FullName = "System.Int32"}

    I'm really confused because the the GetById(TransactionManager, int id) method exists in the base class that Sql_CareerProvider inherits from.

    Hopefully this helps a bit more - thanks again for your time!

    James
  • The method names are case-sensitive.  Can you double check the name of the method in your provider to see if it is GetById or GetByID?  The reason I ask is because you use both Id and ID in your EDS declaration.  Thanks.

    Bobby Diaz ------------------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------------------
  • Arrrrgh!! I can't believe that I didn't see that! Thanks so much!

    Ok, so that solves the problem of loading up the values when clicking "Edit", but I still have the issue of the Insert method inserting blank values for all fields, and when I hit "Update", nothing is getting updated.

    Stepping through the code it seems to be that when the object is trying to read the values from the <itemtemplate> in the user control it is not getting any values.

    A snippet of code for the formView in my user control looks like the following:

    <asp:FormView ID="fvCareer" runat="server">
       
        <ItemTemplate>
            <asp:Table ID="Table1" runat="server" CellPadding="3" CellSpacing="1">
                <asp:TableRow ID="TableRow1" runat="server">
                    <asp:TableCell ID="TableCell1" runat="server" SkinID="EditorLabelCell">ID:</asp:TableCell>
                    <asp:TableCell ID="TableCell2" runat="server" SkinID="EditorDataCell">
                        <asp:Label ID="dataID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow ID="TableRow2" runat="server">
                    <asp:TableCell ID="TableCell3" runat="server" SkinID="EditorLabelCell">Title:</asp:TableCell>
                    <asp:TableCell ID="TableCell4" runat="server" SkinID="EditorDataCell">
                        <asp:TextBox runat="server" id="dataTitle" Text='<%# Bind("Title") %>' MaxLength="100"></asp:TextBox><asp:RequiredFieldValidator ID="ReqVal_dataTitle" runat="server" Display="Dynamic" ControlToValidate="dataTitle" ErrorMessage="Required"></asp:RequiredFieldValidator>
                    </asp:TableCell>
                </asp:TableRow>

    ...

    Thanks again for all of the help! Any ideas on how to get it to read these values from the form when inserting and updating?

    Thanks,

    James


  • ARrrgh again!!

    As it turns out using the <asp:Table> control is what screws everything up. As soon as I take the controls out of that element it inserts and updates fine.

    Is this a known issue? Or am I just doing something crazy on my side?

    On another note, when generating the code and using the option to generate the web admin controls, I am still having the issue where the .designer file is not getting generated, or at least, the declarations for all of the controls in the page are not getting generated.

    Anyone else have this problem?

    Thanks,

    James
  • My guess would be that the Bind() method is not able to find the datasource because it might just do something like this.Parent.DataSource, and your table doesn't have a datasource.  That's a blatant guess however, and i could totally be wrong.

    We'll check into the bug issue.


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------

  • Ah, it seems that I should be banned from posting here :P

    I got the latest version from source control, and now all controls etc. work wonderfully! So don't worry about that bug.

    That web site admin interface that you guys are building is AWESOME!! :)

    Thanks so much for the work that you are all putting into this!

    James
  • The asp:table bug is a known issue:

    http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=1e64e5f4-bac4-4691-906a-76f3664cc330

    The earlier versions of the web abmin controls still used asp:table tags to allow using skins for formatting, but it requires additional controls to handle the binding.

    If I remember correctly, the .designer issue only rears it's head when using the web project format rather than the default web site format for you web sites...

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

  • Ah ok, thanks for clearing that up for me :)

    Heh, that bug cost me more hours than I'd care to mention :P
  • FYI, There was a recent bug fix so that EntityDataSource will throw an exception if the there is a typo, and it can't find the method to invoke on the entity.

    The bug didn't exist in GetMethod, rather that InvokeMethod just didn't raise an exception when GetMethod didn't return anything.
Page 1 of 1 (12 items)