CodeSmith Community
Your Code. Your Way. Faster!

The entity object cannot be null.

Latest post 08-15-2008 9:27 AM by Joe Mayo. 4 replies.
  • 04-22-2008 2:24 PM

    • rithomas
    • Not Ranked
    • Joined on 04-13-2007
    • Posts 2
    • Points 100

    The entity object cannot be null.

    When I attempt to save a record from the entitygridview, I get this error:

    [NullReferenceException: The entity object cannot be null.]
    IGD.Web.Data.BaseDataSourceView`2.ValidateEntity(Entity entity, IDictionary keys) in C:\Projects\xxx\IGD.Web\Data\BaseDataSource.cs:1940
    IGD.Web.Data.BaseDataSourceView`2.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) in C:\Projects\xxx\IGD.Web\Data\BaseDataSource.cs:1558
    System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +78
    System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1215
    System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +837
    System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
    System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +117
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
    System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
    System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +132
    System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

     

    Here is my code:

        <data:EntityGridView DataKeyNames="ManufacturerID" ID="gridManufacturer" runat="server" DataSourceID="dataManufacturer" AllowExportToExcel="True" AllowMultiColumnSorting="False" AllowPaging="True" AutoGenerateColumns="False" DefaultSortColumnName="ManufacturerId" DefaultSortDirection="Ascending" ExportToExcelText="Excel" PageSelectorPageSizeInterval="10">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="ManufacturerId" HeaderText="ManufacturerId" ReadOnly SortExpression="ManufacturerId" />
                <asp:BoundField DataField="ManufacturerName" HeaderText="ManufacturerName" SortExpression="ManufacturerName" />
                <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
            </Columns>
        </data:EntityGridView>

        <data:ManufacturerDataSource ID="dataManufacturer" SelectMethod="GetPaged" runat="server" EnablePaging="True">
            <DeepLoadProperties Method="IncludeChildren" Recursive="False">
            </DeepLoadProperties>
        </data:ManufacturerDataSource>

     

    Am I missing something?  The Auto-generated admin screen doesn't work right, either.  No matter what record you edit, it always updates where ManufacturerID = 1. 

    • Post Points: 65
  • 05-08-2008 9:15 AM In reply to

    • blake05
    • Top 25 Contributor
    • Joined on 04-03-2008
    • Wisconsin
    • Posts 416
    • Points 7,635

    Re: The entity object cannot be null.

    Hello,

    Could you email me your database schema and I will take a look at this.

    Thanks

    -Blake

    Blake Niemyjski

    CodeSmith Tools, LLC Support Specialist

    Blog: http://windowscoding.com/blogs/blake/

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

    • Post Points: 5
  • 08-13-2008 2:34 PM In reply to

    • Joe Mayo
    • Not Ranked
    • Joined on 08-13-2008
    • Posts 2
    • Points 40

    Re: The entity object cannot be null.

    Have you figured this out?

    Thanks,

    JoeM

    • Post Points: 35
  • 08-13-2008 2:52 PM In reply to

    • blake05
    • Top 25 Contributor
    • Joined on 04-03-2008
    • Wisconsin
    • Posts 416
    • Points 7,635

    Re: The entity object cannot be null.

    Hello,

    I never received your email. Could you please resend ( BNiemyjski AT codesmithtools d0t com ).

    Thanks

    -Blake Niemyjski

    Blake Niemyjski

    CodeSmith Tools, LLC Support Specialist

    Blog: http://windowscoding.com/blogs/blake/

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

    • Post Points: 35
  • 08-15-2008 9:27 AM In reply to

    • Joe Mayo
    • Not Ranked
    • Joined on 08-13-2008
    • Posts 2
    • Points 40

    Re: The entity object cannot be null.

    Reply |Contact |Answer

    In my case, the problem was due (1) to there being no primary key: netTiers only works with the updating via FormView etc when it knows how to create a unique key for each row. And secondly (2) I was using a view, and trying to update data via a view, which netTiers doesn't support, and it appears that setting a primary key (or any other index) on a view doesn't seem to work correctly. I ended up doing things the manual way and just updating the two tables involved manually. :-( But I got tired of swimming up stream.

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