TypedView Bug

Posts   
 
    
Posts: 15
Joined: 01-Oct-2003
# Posted on: 02-Oct-2003 17:17:52   

I think I have found a Typed View Bug.

Steps to reproduce:

Create a View in your database Create a Typed View in the designer Generate Try to query the view applying a Sort Filter, the Order by Clause will be the actual Entity Name rather then the typed view name.

I captured this in the Sql Profiler:-

exec sp_executesql N'SELECT [CategoryView].[CategoryID],[CategoryView].[ForumID],[CategoryView].[CategoryTitle],[CategoryView].[CategoryDescription],[CategoryView].[SortOrder],[CategoryView].[TopicCount],[CategoryView].[PostCount],[CategoryView].[LastPostDate],[CategoryView].[LastPostUserID],[CategoryView].[DateCreated],[CategoryView].[DateLastModified],[CategoryView].[IsCategoryPrivate],[CategoryView].[IsCategoryLocked],[CategoryView].[IsActiveTopic],[CategoryView].[UserName]

FROM [dbo].[CategoryView]

WHERE ( [CategoryView].[ForumID] = @ForumID1)

ORDER BY [ForumCategory].[SortOrder] ASC', N'@ForumID1 int', @ForumID1 = 4

So as you can see the Order By should be [CategoryView].[SortOrder] not [ForumCategory].[SortOrder]

-Scott

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 02-Oct-2003 17:42:56   

Can you please paste the code you used to construct the sort clause? I think the sort clause create code isn't correct then

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 02-Oct-2003 17:47:50   

This works like a charm:

InvoicesTypedView invoices = new InvoicesTypedView();
IPredicateExpression invoicesFilter = new PredicateExpression();
FieldCompareValuePredicate filterElement = PredicateFactory.CompareValue(InvoicesFieldIndex.OrderID, ComparisonOperator.GreaterThan, 11000);
invoicesFilter.Add(filterElement);
ISortExpression sorterInvoices = new SortExpression(SortClauseFactory.Create(InvoicesFieldIndex.ExtendedPrice, SortOperator.Descending));
invoices.Fill(0, sorterInvoices, true, invoicesFilter);

Check the line where the sortexpression is constructed. Because the SortClauseFactory contains a lot of overloaded methods which accept different field index types, you can specify for example another field index than the view name to create the sortclause. This then will cause a sortclause that contains a field reference that is not in the view. I think you specified the wrong field index when creating the sortclause simple_smile

So if I do: ISortExpression sorterInvoices = new SortExpression(SortClauseFactory.Create(CustomerFieldIndex.CustomerID, SortOperator.Descending)); in the piece of code above, the code will compile, however the query will contain an order by on Customers.CustomerID, which is not in the view. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 15
Joined: 01-Oct-2003
# Posted on: 03-Oct-2003 00:59:42   

Otis wrote:

This works like a charm:

InvoicesTypedView invoices = new InvoicesTypedView();
IPredicateExpression invoicesFilter = new PredicateExpression();
FieldCompareValuePredicate filterElement = PredicateFactory.CompareValue(InvoicesFieldIndex.OrderID, ComparisonOperator.GreaterThan, 11000);
invoicesFilter.Add(filterElement);
ISortExpression sorterInvoices = new SortExpression(SortClauseFactory.Create(InvoicesFieldIndex.ExtendedPrice, SortOperator.Descending));
invoices.Fill(0, sorterInvoices, true, invoicesFilter);

Check the line where the sortexpression is constructed. Because the SortClauseFactory contains a lot of overloaded methods which accept different field index types, you can specify for example another field index than the view name to create the sortclause. This then will cause a sortclause that contains a field reference that is not in the view. I think you specified the wrong field index when creating the sortclause simple_smile

So if I do: ISortExpression sorterInvoices = new SortExpression(SortClauseFactory.Create(CustomerFieldIndex.CustomerID, SortOperator.Descending)); in the piece of code above, the code will compile, however the query will contain an order by on Customers.CustomerID, which is not in the view. simple_smile

Hehe, you are exactly right, I am such an idiot! I shouldn't code late at night flushed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Oct-2003 10:52:06   

Nah, it's not idiotic, it's a mistake that can happen simple_smile I'll close the thread simple_smile

Frans Bouma | Lead developer LLBLGen Pro