THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

Possible Bug when Auto-Paging on a single Table?

rated by 0 users
This post has 6 Replies | 1 Follower

Top 75 Contributor
Posts 34
DanM Posted: 01-30-2008 3:39 AM

Hi,

I noticed what seems to be an issue with your esDataSource AutoPaging yesterday. I wondered if you could confirm if it is a bug or not. Basically, In the DataSource's esSelect event handler, I set the DataSource's query with

Code:
protected void coursesDataSource_esSelect(object sender, esDataSourceSelectEventArgs e)
{
   e.Collection = new CourseCollection();
   e.Query = GetSearchQuery();
}

Initially, GetSearchQuery() ran a select on just one table

Code:
private CourseQuery GetSearchQuery()
{
   CourseQuery course = new CourseQuery("course");

      course.Select(
         course.CourseId,
         course.Date.As("CourseDate"),
         course.CustomerId.As("CustomerName"),
         course.ProductCode.As("ProductName"),
         course.AddressPostCode.As("Location"),
         course.ExpectedNumberOfDelegates.As("ExpectedDelegates"),
         course.Cost.As("ConfirmedDelegates"),
         course.StatusId.As("Status"));

   return course;
}

But when bound into the GridView, ASP.NET returned a lot of errors saying that many multiple.valued identifiers could not be bound to the GridView. Doing a quick check, this was because ES was generating the follwoing invalid command

Code:
WITH [withStatement] AS 
(SELECT course.[CourseId],
	course.[Date] AS 'CourseDate',
	course.[CustomerId] AS 'CustomerName',
	course.[ProductCode] AS 'ProductName',
	course.[AddressPostCode] AS 'Location',
	course.[ExpectedNumberOfDelegates] AS 'ExpectedDelegates',
	course.[Cost] AS 'ConfirmedDelegates',
	course.[StatusId] AS 'Status' , 
	ROW_NUMBER() OVER( ORDER BY course.Date ASC) AS ESRN 
FROM [Course] course) 
SELECT course.[CourseId],
	course.[Date] AS 'CourseDate',
	course.[CustomerId] AS 'CustomerName',
	course.[ProductCode] AS 'ProductName',	
	course.[AddressPostCode] AS 'Location',
	course.[ExpectedNumberOfDelegates] AS 'ExpectedDelegates',
	course.[Cost] AS 'ConfirmedDelegates',
	course.[StatusId] AS 'Status'  
FROM [withStatement] WHERE ESRN BETWEEN 1 AND 15

However, if I added the first of (many) joins to the search query like so

Code:
private CourseQuery GetSearchQuery()
{
   CourseQuery course = new CourseQuery("course");
   UserCustomerQuery customer = new UserCustomerQuery("customer");

      course.Select(
         course.CourseId,
         course.Date.As("CourseDate"),
         customer.Name.As("CustomerName"),
         course.ProductCode.As("ProductName"),
         course.AddressPostCode.As("Location"),
         course.ExpectedNumberOfDelegates.As("ExpectedDelegates"),
         course.Cost.As("ConfirmedDelegates"),
         course.StatusId.As("Status"));
      course.InnerJoin(customer).On(course.CustomerId == customer.UserId);

   return course;
}

Then all the binding works fine and the GridView is populated correctly. And the SQL that ES generates looks like this

Code:
WITH [withStatement] AS 
(SELECT course.[CourseId],
	course.[Date] AS 'CourseDate',
	customer.[Name] AS 'CustomerName',
	course.[ProductCode] AS 'ProductName',
	course.[AddressPostCode] AS 'Location',
	course.[ExpectedNumberOfDelegates] AS 'ExpectedDelegates',
	course.[Cost] AS 'ConfirmedDelegates',
	course.[StatusId] AS 'Status' , 
	ROW_NUMBER() OVER( ORDER BY course.Date ASC) AS ESRN 
FROM [Course] course 
	INNER JOIN [UserCustomer] customer ON course.[CustomerId] = customer.[UserId]) 
SELECT * FROM [withStatement] WHERE ESRN BETWEEN 1 AND 15

Which is pretty different from the first SQL generated without the join. The first SQL statement definitely doesn't work. Thought you should know.

 

Top 10 Contributor
Posts 3,881

On your first example you are using the syntax that is used for joins, however, you are not using a join. Basically, on the first example you should be setting the collection's "Query" to the GetSearchQuery() by passing the Query in and filling it in, then not setting the "e.Query" variable.

This is our fault for not having better documentation. There are two samples of esDataSource installed with EntitySpaces, you can find them under the EntitySpaces folder. There is one page for joins and one without that show you how to use the esDataSource.

I hope this helps. We are going to improve esDataSource quite a bit even on ES2008 although it works quite well now. 

 

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 75 Contributor
Posts 34

Hi Mike,

Thanks for clarifying this.

I gotta think though that if you're planning to do joins as I was but do a single table query first, it's mighty inconvenient that this approach of doing a no-table join just doesn't work. If the SQL generated included SELECT * from [withStatement] as it does when one table is being joined to another, everything would work fine. Looking forward to ES2008 to see what changes you've made

Dan

Top 10 Contributor
Posts 265

I agree with Dan. It would be much nicer if this approach worked for both single table queries and join queries.

Leigh
Top 10 Contributor
Posts 3,881
We can make esDataSource smart enough to handle that for sure.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 10 Contributor
Posts 3,881
I just tested this, this has been fixed now in ES2008 naturally (the problem went away due to some internal changes we made anyway).

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 10 Contributor
Posts 265

Nice one Mike. I'm looking forward to the ES 2008 final release.

Leigh
Page 1 of 1 (7 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC