The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

MySQL View AutoPaging/AutoSorting problem

Last post 09-06-2007, 1:48 PM by Scott.Schecter. 5 replies.
Sort Posts: Previous Next
  •  09-06-2007, 11:55 AM 4994

    MySQL View AutoPaging/AutoSorting problem

    Hello:

    I've got the following setup:

    MySQL v5.1
    MySQL Connector 5.0.7
    ES 819
    C#
    XP SP2
    VS2005 SP1

    I'm using the ES Datasource and design time binding with the standard GridView component.  ASP.Net 2.0, etc.

    I have created a view in MySQL that has 5 columns.  The first is named "Id" and contains the PrimaryKey from one of the files.  The other four are just varchar fields.  Everything looks normal.  I've created the esCreateEntity event and the esSelect event.   When I set AllowSorting/AutoSorting (both places) to true and try to generate the page I get the following:

     

    Code:
    Server Error in '/NAPSWS_MySQL' Application.
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
    EntitySpaces.Web.esDataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +384
    System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
    System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
    System.Web.UI.WebControls.GridView.DataBind() +4
    System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
    System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
    System.Web.UI.Control.EnsureChildControls() +87
    System.Web.UI.Control.PreRenderRecursiveInternal() +41
    System.Web.UI.Control.PreRenderRecursiveInternal() +161
    System.Web.UI.Control.PreRenderRecursiveInternal() +161
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360


    Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832
     

    If I turn off the AutoSorting/AllowSorting it loads just fine.

    A second problem is when I turn on AutoPaging/AllowPaging.

    I get the correct number of pages at the bottom of the grid, and the first 10 rows, however, when I click on one of the pages, the header appear but no lines.

    If I don't use AutoPaging all the rows appear.

    Thank you for your help!

    Phil Mickelson

  •  09-06-2007, 12:05 PM 4995 in reply to 4994

    Re: MySQL View AutoPaging/AutoSorting problem

    Awful hard to diagnose without any code. Compare your code to this example and see if you can spot any differences. If not post the relavent code and we will take a look.

     


    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  09-06-2007, 12:42 PM 4996 in reply to 4994

    Re: MySQL View AutoPaging/AutoSorting problem

    When you have either AutoPaging or AutoSorting turned on you do not load the collection, the esDataSource does, perhaps that's the issue?
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-06-2007, 12:44 PM 4997 in reply to 4995

    Re: MySQL View AutoPaging/AutoSorting problem

    Sorry.  I've included the code below.  I also probably didn't emphasize a few things:

    1.  This is a view, not a standard table.

    2.  When I run standard tables it works perfectly.

    3.  This view is made up of data from three separate tables.

    4.  As long as AutoPaging/AutoSorting are set to False, the base grid appears just fine.  Just 266 rows and no sort columns.

    5.  In the code there is an esCreateEntity event.  However, it's never called.  I was trying to figure out how to find the specific row without a primary key and was going to try that process.  Was I right? 

    Thank you again for your help!  Code follows:

     

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
    
    <%@ Register Assembly="EntitySpaces.Web" Namespace="EntitySpaces.Web" TagPrefix="cc1" %>
    
    "-//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" >Untitled Page
    "server">
        
    
        "form1" runat="server">
        
    "GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="EsDataSource1" AllowSorting="True"> "Id" HeaderText="Id" SortExpression="Id" /> "ModelName" HeaderText="ModelName" SortExpression="ModelName" /> "ModelSeries" HeaderText="ModelSeries" SortExpression="ModelSeries" /> "ModelStyle" HeaderText="ModelStyle" SortExpression="ModelStyle" /> "Elevation" HeaderText="Elevation" SortExpression="Elevation" />
    "EsDataSource1" runat="server" OnesCreateEntity="EsDataSource1_esCreateEntity" OnesSelect="EsDataSource1_esSelect" AutoSorting="True" EnableViewState="False" />
     
    Code:
    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 BusinessObjects;
    
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                count_models();
            }
        }
    
        protected void EsDataSource1_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e)
        {
            ModelGrid entity = new ModelGrid();
    
            if (e.PrimaryKeys == null)
                entity.AddNew();
            else
            {
                entity.Query.Where(entity.Query.Id == (uint)e.PrimaryKeys[0]);
                entity.Query.Load();
                //entity.LoadByPrimaryKey((uint)e.PrimaryKeys[0]);
            }
            // Assign the Entity
            e.Entity = entity;
    
        }
    
        protected void EsDataSource1_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e)
        {
            ModelGridCollection coll = new ModelGridCollection();
            e.Collection = coll;
        }
    
    
        protected void count_models()
        {
            ModelGrid eModel = new ModelGrid();
            eModel.Query.es.CountAll = true;
            eModel.Query.es.CountAllAlias = "Count";
            if (eModel.Query.Load())
            {
                EsDataSource1.TotalRowCount = Convert.ToInt32(eModel.GetColumn("Count"));
            }
            GridView1.Sort(ModelGridMetadata.ColumnNames.ModelSeries, SortDirection.Ascending);
        }
    
    }
    
  •  09-06-2007, 1:33 PM 4998 in reply to 4997

    Re: MySQL View AutoPaging/AutoSorting problem

    Ok.  So how much longer are you guys going to put up with me?  I've been writing software for almost 30 years now.  You'd think I would wait just a little longer before writing about a problem.  However, these new fangled forums are just too easy!  Plus, it doesn't help that you try to respond as quickly as possible!  (All tongue firmly in cheek.)

    So, if figured out both problems:

    1.  If I remove the Gridview1.Sort.... line in the count_models procedure no more errors and sorting works perfectly, all columns.  Is this due to my using an "order by" value that doesn't match what I was sorting by?  Or,  is there something else I'm missing?  I've never used Views before and I've fallen in love.  Is there something inherently wrong with them?

    2.  To fix the paging issue I changed the esSelect event so that it looks like this now:

     

    Code:
        protected void EsDataSource1_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e)
        {
            ModelGridCollection coll = new ModelGridCollection();
            e.Collection = coll;
            e.Arguments.TotalRowCount = count_models();
        }
    
    
        protected int count_models()
        {
            ModelGrid eModel = new ModelGrid();
            eModel.Query.es.CountAll = true;
            eModel.Query.es.CountAllAlias = "Count";
            if (eModel.Query.Load())
            {
                return Convert.ToInt32(eModel.GetColumn("Count"));
            }
            else
                return 0;
            //GridView1.Sort(ModelGridMetadata.ColumnNames.ModelSeries, SortDirection.Ascending);
        }
    

    Just to recap; I don't have to do these for normal tables.

    Thanks again for creating such a great product and doing your best to help those of us who, even after all these years, are still handicapped!

    Phil Mickelson 

  •  09-06-2007, 1:48 PM 4999 in reply to 4998

    Re: MySQL View AutoPaging/AutoSorting problem

    1) Yes that was your issue;) Setting the sort in essence sets the order by initially. You should not need to include an order by if you are setting the initial sort explicitly.

    2) I am still unsure on this one, setting the EsDataSource.TotalRowCount  in load works on all my tests? Perhaps Mike will have some more ideas on that one.

    Thanks for your kind words, we always appreciate them, as we pride ourselves on fanatic support. 


    Regards,

    Scott Schecter
    EntitySpaces | My Site
View as RSS news feed in XML