LLBLGenDataSource2 and Sorting

Posts   
1  /  2  /  3
 
    
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 23-May-2006 21:28:30   

I wish I could add it at design time, but as far as I know this isn't possible.

Another issue: Since upgrading to the latest beta a number of my gridviews are throwing exceptions in the designer:

When using a TypedList in the data source: "There was an error rendering the control. DataBinding: System.Data.DataRowView does not contain a property with the nane 'ThreadId'".

This seems related to the DataKeyNames property. My data keys are set to "ThreadId,StaffRef"

Also, when using EntityCollection in the data source I get a different message in the designer: "There was an error rendering the control. Property accessor 'TutorGroup' on object DataLibrary.EntityClasses.StudentMessageEntity threw the following exception: 'Object reference not set to an instance of an object'

This only seems to occur if there are custom properties in the class definition.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 23-May-2006 22:10:46   

First: close all forms in vs.net, then close vs.net, then restart vs.net then rebuild, then open a form again. It should fix the first error.

Custom properties? You mean properties added to the entity class? Or custom properties added to the entity in the llblgen pro designer ?

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 23-May-2006 22:17:46   

Unfortunately restarting VS and rebuilding did not fix the first error.

Regarding error #2, by custom properties I meant properties added to the entity class. Sorry for the confusion.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 23-May-2006 22:36:28   

That's odd, as I used a custom property added to my customerentity class to test the client side sorting.

So I think it's related to more settings. Could you give more details about the parameters of the datasourcecontrol / bound grid ?

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 23-May-2006 22:45:47   

This is the declaration for the grid:


    <asp:GridView AllowPaging="True" PageSize="15" AllowSorting="True" DataKeyNames="FlaggedBySender,MsgID"
        AutoGenerateColumns="False" runat="server" ID="gvStudentSentStatus" DataSourceID="dsMessages"
        OnRowDataBound="gvStudentSentStatus_RowDataBound" OnRowCommand="gvStudentSentStatus_RowCommand">
        <Columns>
            <asp:ButtonField CommandName="flag" HeaderText="Flag" SortExpression="FlaggedBySender"
                Text="Flag" />
            <asp:HyperLinkField SortExpression="Surname" HeaderText="Surname" DataNavigateUrlFields="StudentRef"
                DataNavigateUrlFormatString="~/students/student_information.aspx?viewstudentuser={0}"
                DataTextField="Surname" />
            <asp:HyperLinkField SortExpression="Forename" HeaderText="Forename" DataNavigateUrlFields="StudentRef"
                DataNavigateUrlFormatString="~/students/student_information.aspx?viewstudentuser={0}"
                DataTextField="Forename" />
            <asp:BoundField HeaderText="TG" DataField="TutorGroup" SortExpression="TutorGroup" />
            <asp:BoundField HeaderText="Date Sent" DataField="DateOfMessage" SortExpression="DateOfMessage" />
            <asp:BoundField HeaderText="Message" DataField="Message" SortExpression="Message" />
            <asp:BoundField HeaderText="Date Received" DataField="ReceivedDate" SortExpression="ReceivedDate" />
            <asp:BoundField HeaderText="Priority" DataField="PriorityDescription" SortExpression="Priority" />
        </Columns>
    </asp:GridView>

And the datasource:


 <cc1:LLBLGenProDataSource2 ID="dsMessages" LivePersistence="false" runat="server"
        EnablePaging="True" OnPerformGetDbCount="dsMessages_PerformGetDbCount" OnPerformSelect="dsMessages_PerformSelect"
        AdapterTypeName="DataLibrary.DatabaseSpecific.DataAccessAdapter, DataLibraryDBSpecific"
        DataContainerType="EntityCollection" EntityFactoryTypeName="DataLibrary.FactoryClasses.StudentMessageEntityFactory, DataLibrary" SortingMode="ClientSide">
    </cc1:LLBLGenProDataSource2>

This is the code for the custom property:


 public string TutorGroup
        {
            get { return this.Student.TutorGroup; }
        }

dregs
User
Posts: 19
Joined: 28-May-2005
# Posted on: 24-May-2006 00:10:45   

When you said

The one line of code was required to set the pageindex of the formview so I could use 1 datasource

Could you show me the one line of code simple_smile

I have also seen the error about datakeys when using the a TypedList

There was an error rendering the control. DataBinding: System.Data.DataRowView does not contain a property with the name 'ID'

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 24-May-2006 09:56:25   

dregs wrote:

When you said

The one line of code was required to set the pageindex of the formview so I could use 1 datasource

Could you show me the one line of code simple_smile

Sure simple_smile


protected void _ordersGrid_SelectedIndexChanged( object sender, EventArgs e )
{
    _newOrderFormView.PageIndex = _ordersGrid.SelectedIndex;
}

I have also seen the error about datakeys when using the a TypedList

There was an error rendering the control. DataBinding: System.Data.DataRowView does not contain a property with the name 'ID'

In what context did this happen exactly? Could you give more specifics how to create the situation in where this happens? As my testpage with a typedlist doesn't bug...

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 24-May-2006 13:42:49   

Jez wrote:

Also, when using EntityCollection in the data source I get a different message in the designer: "There was an error rendering the control. Property accessor 'TutorGroup' on object DataLibrary.EntityClasses.StudentMessageEntity threw the following exception: 'Object reference not set to an instance of an object'

This only seems to occur if there are custom properties in the class definition.

I can't reproduce this. I have a gridview, and a datasource, set to entitycollection which shows customers, which have a custom property (string). I set everything the same as you have, no luck in reproducing it. However I'm thinking this might be a vs.net thing still. I sometimes have this too, because the ORMSupportClasses is different/ generated code assembly is different than what the webpage designer uses. Compiling it again doesn't help, only closing the forms, closing vs.net, restarting vs.net, FIRST rebuild teh solution then open a form.

Also, if you click on the datasource' smarttag, Configure Data Source, that works? Or do you get "wrong entrypoint" or something like that? Also if you select on the smarttag in the grid the option to edit fields, do you get the custom property in the list of bound fields?

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 24-May-2006 13:48:07   

Jez wrote:

Another issue: Since upgrading to the latest beta a number of my gridviews are throwing exceptions in the designer:

When using a TypedList in the data source: "There was an error rendering the control. DataBinding: System.Data.DataRowView does not contain a property with the nane 'ThreadId'".

This seems related to the DataKeyNames property. My data keys are set to "ThreadId,StaffRef"

I see this error now too when I select a field as the keyfield in the grid. You could set a keyfield before?

It's strange, the columns are there, the dataview just doesn't return any columns all of a sudden... Very strange as nothing changed in that area.

(edit) looking at the schema meta-data, everything is returned correctly (which shows, as you'll see the column show up normally).

The point is though that the typedview and typedlist classes are datatables ,and bound to the grid as a dataview (as a datatable does). This means that a row in the grid is bound to a datarowview. This class doesn't have strong named properties. However it's beyond me why it's a problem for the PK fields and not for the columns...

(I also wonder, why you would want a pk field in the grid which is bound to a typedlist?)

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 24-May-2006 13:56:56   

I have tried the following numerous times: - Closing all web forms in VS - Closing VS - Reopening VS - Rebuilding - Opening web form

The problem still occurs.

However, I believe I have made some progress in tracking this down. This is the code from my custom property:


        public string TutorGroup
        {
            get { return this.Student.TutorGroup; }
        }

In this example, "Student" a field on a relation (StudentMessage is related to Student via a m:1 relationship). If I change the property to something simpler (eg return "test"; rather than return this.Student.TutorGroup) then the error disappears from the designer. If I put the code back, then the error returns.

Clicking "Configure Data Source" on the smart tag seems to work without any problems. Interestingly, if I click "New Data Source" in the grid's smart tag (from the datasources dropdown) I receive the following error (although I don't think this is a related problem):

Error setting value '<New data source...>' to property 'DataSourceID'.  Details: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 24-May-2006 13:59:08   

Otis wrote:

I see this error now too when I select a field as the keyfield in the grid. You could set a keyfield before?

I don't think this problem is related to the latest beta build. I seem to recall it in previous builds too, although I cannot remember when I started to notice this.

The EntityCollection issue is only present in the most recent build.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 24-May-2006 14:03:56   

Ok, I think I now see what the problem might be. this.Student is of course null at design time, so that causes the problem there. My property indeed returns a concatenation of 2 properties of the same entity.

I'll see if I can repro it with a property similar to yours. You should however always test on null in properties like that. So instead, write the property like:


public string TutorGroup
{
    get
    {
        string toReturn = string.Empty;
        if(this.Student!=null)
        {
            toReturn = this.Student.TutorGroup;
        }
        return toReturn;
    }
}

The typedlist problem is likely something I can't solve, as I return all info that's needed for the grid. (and as there is no documentation WHATSOEVER about this, this is truly trial/error... in fact the schema classes used are rebuilds of what .NET uses internally as these classes are internal, go figure disappointed )

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 24-May-2006 14:08:47   

Otis wrote:

in fact the schema classes used are rebuilds of what .NET uses internally as these classes are internal, go figure disappointed )

How very helpful of MS wink

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 24-May-2006 15:10:13   

Jez wrote:

Otis wrote:

in fact the schema classes used are rebuilds of what .NET uses internally as these classes are internal, go figure disappointed )

How very helpful of MS wink

That's an understatement wink . I wrote a very long email to Guthrie a couple of months ago with all the stuff I missed, they were happy with the feedback and would work hard to get it better documented... but when that will be, I have no idea wink

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 24-May-2006 16:07:19   

The property error you see with the entitycollection is caused by the grid reading the sample data (you know, those 5 rows in the grid in the designer). The grid simply calls Get on the property descriptors, so reads directly from the entity.

I can't avoid this, as it's simply calling directly your property code. So work around this by making your properties more robust: test for null. This can't hurt either, as it will then also avoid crashes at runtime in other scenarios simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 24-May-2006 16:55:06   

Ok, thanks for investigating this. I'll put some null checks in simple_smile

On a semi-related note, when a gridview is bound to datasource with livepersistence=true, if you set the .SorterToUse property in the Page_Load event then you can no longer sort the grid by clicking its column headings. Is this by design? If so, is there a way round this?

Thanks simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 24-May-2006 17:01:07   

The sortcolumn you click on is appended to the sortexpression already set in the datasourcecontrol. So this means it might result in the same order as the original sorter is already doing all the sorting.

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 24-May-2006 17:17:22   

I see. Would the best way around this be to clear the SorterToUse in the GridView's Sorting event or is there a better way?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 24-May-2006 19:10:23   

I'm thinking about doing the clear for you when a sort is issued by a bound control. It's about what the user expects: the column is clicked, so the sorting is supposed to be the column sort, not some sort already set and WITHIN that sort, the column sort...

So how it's done at the moment is confusing. In winforms, the entityview is also sorted solely on the column(s) specified.

I'll make the change in the next build, unless some people disagree. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 30-May-2006 13:53:28   

Another sorting related issue:

If I have a datasource with livepersistence="true" and SortingMode="clientSide" then any initial sorter set in the code behind seems to be ignored.

eg:


if(!IsPostBack)
{
SortExpression sorter = (SheetCodeFields.SheetCodeDescription | SortOperator.Ascending) & (SubjectFields.SubjectArea | SortOperator.Ascending);
dsStatement.SorterToUse = sorter;
}
//No initial ORDER BY is applied to the query

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 30-May-2006 14:05:19   

yes, because that's what's needed otherwise any column sort action sorts inside the initial sorter which can result in no changes in the data.

Or is this occuring always, thus also when you don't have a column sort?

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 30-May-2006 14:29:14   

Hi Frans,

This is always happening - even without a column sort in place. What I was hoping to do was: - Set an initial sorter when the page loads. - Then when a column is clicked then my initial sorter is discarded and the clientside sorting takes over.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 30-May-2006 14:35:45   

Looking at the code I don't see how this can happen, but I'll do some tests. Your expectations are indeed correct, that's how the code should work. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 30-May-2006 18:28:12   

I can't reproduce it... Page:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default9.aspx.cs" Inherits="Default9" %>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Client-side sorting with an initial sorter. It should be applied to the data before it's bound to the grid.
    Initial sorter is set in the code behind and sorts on country.<br />
        &nbsp;<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerId" DataSourceID="_customersDS">
            <Columns>
                <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" ReadOnly="True" SortExpression="CustomerId" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
                <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle" />
                <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
                <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
                <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
                <asp:BoundField DataField="CompanyNameCustomerId" HeaderText="CompanyNameCustomerId" SortExpression="CompanyNameCustomerId" />
            </Columns>
        </asp:GridView>
    
    </div>
        <cc1:LLBLGenProDataSource2 ID="_customersDS" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.CustomersEntityFactory, NWTest" SortingMode="ClientSide">
        </cc1:LLBLGenProDataSource2>
    </form>
</body>
</html>

codebehind:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SD.LLBLGen.Pro.ORMSupportClasses;
using NWTest.HelperClasses;

public partial class Default9 : System.Web.UI.Page
{
    protected void Page_Load( object sender, EventArgs e )
    {
        if( !Page.IsPostBack )
        {
            SortExpression sorter = new SortExpression();
            sorter.Add( (CustomersFields.Country | SortOperator.Ascending) );
            _customersDS.SorterToUse = sorter;
        }
    }
}

data is sorted on country, ascending...

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 30-May-2006 18:33:37   

Strange. I will do some further investigating.

1  /  2  /  3