LLBLGenProDataSourceView2.ExecuteUpdate Excecption

Posts   
 
    
yowl
User
Posts: 271
Joined: 11-Feb-2008
# Posted on: 30-Oct-2008 01:26:39   

Hi,

I'm using LLBLGenPro 2.6 with Postgres(Npgsql 1.0.0.0) and I have a problem with LLBLGenProDataSourceView2 and the GridView in ASP.Net. I have LivePersistance=True (setting False gives same error), and I get this error when trying to update a row in the grid:

[ORMGeneralOperationException: There are no primary key fields specified in the bound control and/or the bound control didn't specify any primary key fields. Update can't continue.] SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +229 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

A bit of digging indeed reveals that the keys parameter has a count=0. In the LLBLGen designer I can see that my entity has IsPK = true on one of the columns (Id), so I would have thought it would pick that up?

Here is the aspx:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MaintainCourses.aspx.cs" Inherits="MaintainCourses" Title="Untitled Page" %>

<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="llblgenpro" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> Category <aspsmile ropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </aspsmile ropDownList> <br />

<br />
<div class="todoheader">
    Courses
</div>
        <asp:GridView ID="GridView1" runat="server" 
            AllowPaging="True" 
            AutoGenerateColumns="False" 
            CssClass="gridview"
            AlternatingRowStyle-CssClass="even"
            GridLines="None"
            DataSourceID="LLBLGenProDataSource1" Width="328px" 
            onrowcancelingedit="GridView1_RowCancelingEdit" 
            onrowupdated="GridView1_RowUpdated" onrowupdating="GridView1_RowUpdating">
            <Columns>
                <asp:CommandField ShowSelectButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="Id" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="CategoryId" HeaderText="Category" 
                    SortExpression="CategoryId" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            </Columns>
            <AlternatingRowStyle CssClass="even" />
        </asp:GridView>
<div class="insertheader">
    Add a new course
</div>
<llblgenpro:LLBLGenProDataSource2 ID="LLBLGenProDataSource1" runat="server" 
    AdapterTypeName="em.DatabaseSpecific.DataAccessAdapter, emDBSpecific" 
    DataContainerType="EntityCollection" 
    EntityFactoryTypeName="em.FactoryClasses.CourseEntityFactory, em" 
onentityupdating="LLBLGenProDataSource1_EntityUpdating1" 
onperformselect="LLBLGenProDataSource1_PerformSelect" 
onperformwork="LLBLGenProDataSource1_PerformWork">
    <SelectParameters>
        <asp:ControlParameter ControlID="DropDownList1" Name="CategoryId" 
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</llblgenpro:LLBLGenProDataSource2>

</asp:Content>

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Oct-2008 05:56:19   
  • Make sure you have the latest runtime libraries available. (this error might appear in old versions)
  • No PK fields found error is often caused by case mismatches between the PK field name of the entity and the name specified in the grid HTML. Check that please (For example, name of PK field is 'OrderId' and the name specified in the formView is OrderID. This doesn't match)
  • Try add DataKeyNames to the grid.
David Elizondo | LLBLGen Support Team
yowl
User
Posts: 271
Joined: 11-Feb-2008
# Posted on: 30-Oct-2008 19:32:05   

Thanks for the reply. I downloaded the latest runtime and unzipped as specified in the readme. After building I now have in the web Bin folder 2.6.8.1013 of SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll and 2.6.8.819 of SD.LLBLGen.Pro.DQE.PostgreSql.NET20.dll. I checked the case of the bound field holding my primary key property:

<asp:BoundField DataField="Id" ReadOnly="True" SortExpression="Id" />

and I compared that to the property in my entity class:

    /// <summary> The Id property of the Entity Course<br/><br/>
    /// </summary>
    /// <remarks>Mapped on  table field: "course"."id"<br/>
    /// Table field type characteristics (type, precision, scale, length): Integer, 10, 0, 0<br/>
    /// Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
    public virtual System.Int32 Id
    {
        get { return (System.Int32)GetValue((int)CourseFieldIndex.Id, true); }
        set { SetValue((int)CourseFieldIndex.Id, value); }
    }

I think it looks ok, but I get the same error. I then manually set the DataKeyNames as you suggested and that works.

protected void Page_Load(object sender, EventArgs e)
{
    GridView1.DataKeyNames = new[] {"Id"};
}

I now have a workaround, but I shouldn't have to do that right?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 30-Oct-2008 21:16:11   

I think you do unfortunalty - I don't know how else the grid would know how to pick up which columns are the PKs

yowl
User
Posts: 271
Joined: 11-Feb-2008
# Posted on: 30-Oct-2008 23:21:09   

Ah yes, now I see that its supplied in the example in the help flushed . Thanks.