Welcome to the CodeSmith Community!

EntityDataSource woes


A description has not yet been added to this group.

EntityDataSource woes

  • rated by 0 users
  • This post has 11 Replies |
  • 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,

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

    Robert Hinojosa
    Member of the Codesmith Tools, .netTiers, teams

  • Hi Robert,

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

    <data:MultiFormView ID="mfvCareer" runat="server" DataSourceID="_CareerDataSource">
                    <data:TemplatePath Path="/Controls/CareerFields.ascx" />
                    <data:TemplatePath Path="/Controls/CareerFields.ascx" />
                    <b>Customer not found!</b>
                    <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" />
            <data:EntityDataSource ID="_CareerDataSource" runat="server"
                EntityTypeName="TestFrameworkHeadToHead.Entities._Career, TestFrameworkHeadToHead.Entities"
                    <asp:QueryStringParameter Name="EntityId" QueryStringField="ID" />

    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 beta 2 release. I generated the code using the "UseWebAppProject" value set to true. Any other settings that may have an effect?


  • 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!

  • 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">
            <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: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>


    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?



  • 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?


  • 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

  • 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!

  • The asp:table bug is a known issue:


    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)