[bug] Count() fails on entities with TypeConverter on some fields.

Posts   
 
    
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 25-Aug-2008 18:38:03   

Hi,

I'm getting an exception on the following code:


[TestMethod()]
public void LlblgenCountWithTypeConverter()
{
    Console.Write(_linqMetaData.Herindicatie.Count());
}

It probably has something to do with a TypeConverter (GuidStringConverter) on some fields that convert a database type char[36] to and from a Guid, but it shouldn't even have to use it at all in this query?

Output:



: Initial expression to process:
value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource2`1[CC.ECDGenie.Dal.EntityClasses.HerindicatieEntity]).Count()
Method Enter: CreatePagingSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Generated Sql query: 
    Query: SELECT DISTINCT TOP(@top0) COUNT(*) AS [LPAV_] FROM [dbo].[gtb_Herindicatie] [LPLA_1] (nolock)
    Parameter: @top0 : Int64. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1.

Method Exit: CreateSelectDQ
Method Exit: CreatePagingSelectDQ: no paging.
TestCase 'CC.ECDGenie.Dal.UnitTests.LlblgenTests.LlblgenCountWithTypeConverter'
failed: System.NotSupportedException: GuidStringConverter cannot convert from System.Int32.
    at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
    at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
    D:\Projects\dotNet\Net3.5\CC.ECDGenie\MainLine\CC.ECDGenie.TypeConverters\GuidStringConverter.cs(30,0): at CC.ECDGenie.TypeConverters.GuidStringConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
    at SD.LLBLGen.Pro.ORMSupportClasses.ProjectionUtils.FetchProjectionFromReader(List`1 valueProjectors, IGeneralDataProjector projector, IDataReader datasource, Int32 maxNumberOfItemsToReturn, Int32 pageNumber, Int32 pageSize, Boolean clientSideLimitation, Boolean clientSideDistinctFiltering, Boolean clientSidePaging, UniqueList`1 stringCache, Dictionary`2 typeConvertersToRun)
    at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IRetrievalQuery queryToExecute, Dictionary`2 typeConvertersToRun)
    at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IEntityFields2 fields, IRelationPredicateBucket filter, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
    at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteValueListProjection(QueryExpression toExecute)
    at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression)
    at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression)
    at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
    at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
    D:\Projects\dotNet\Net3.5\CC.ECDGenie\MainLine\Dal\CC.ECDGenie.Dal.UnitTests\LlblgenTests.cs(124,0): at CC.ECDGenie.Dal.UnitTests.LlblgenTests.LlblgenCountWithTypeConverter()


0 passed, 1 failed, 0 skipped, took 1,92 seconds.


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 25-Aug-2008 20:38:37   

The first field (with index 0) is the field with the type converter?

Frans Bouma | Lead developer LLBLGen Pro
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 25-Aug-2008 20:56:53   

Otis wrote:

The first field (with index 0) is the field with the type converter?

Nope... See attached screenshot

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 26-Aug-2008 13:12:13   

wtijsma wrote:

Otis wrote:

The first field (with index 0) is the field with the type converter?

Nope... See attached screenshot

It picks the last field in the entity and attaches the aggregate to that field. (for inherited entities, this is necessary). I think your entity has a typeconverter on the last field in that entity (not visible in the screenshot however).

I'll see if I can ignore the typeconverter if necessary.

Frans Bouma | Lead developer LLBLGen Pro
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 26-Aug-2008 13:18:20   

Otis wrote:

It picks the last field in the entity and attaches the aggregate to that field. (for inherited entities, this is necessary). I think your entity has a typeconverter on the last field in that entity (not visible in the screenshot however).

I'll see if I can ignore the typeconverter if necessary.

Yes you're right, the last field has the type converter as well.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 26-Aug-2008 13:32:54   

See the attached fixed ORMsupportclasses lib for the fix. I'll add the linq provider with your fix for the other issue to the other thread for consistency (as the fix for this issue wasn't in the linq provider)

Frans Bouma | Lead developer LLBLGen Pro
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 26-Aug-2008 14:03:16   

Otis wrote:

See the attached fixed ORMsupportclasses lib for the fix. I'll add the linq provider with your fix for the other issue to the other thread for consistency (as the fix for this issue wasn't in the linq provider)

It works now, thanks!