Distinct TypedList including text fields

Posts   
 
    
chrishilton avatar
Posts: 49
Joined: 26-Jun-2007
# Posted on: 04-Oct-2007 13:48:10   

I'm using LLBLGen Pro 2.0.0.0 Final with adapter and .NET 2.0/c# connecting to a SQL Server 2005 dB.

I have a typedlist that includes a field from one of my SQL Server tables with a data type of text. I know that when I call the DataAccessAdapter method FetchTypedList with the allowDuplicates parameter set to false that the executed query does not include the distinct keyword as this is not compatible with text fields. So my question is ...

is there a way to include a text field in a typedlist and return distinct entries without having to filter them out manually?

I was thinking that there may be a way to define the typedlist field by including a cast.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Oct-2007 15:08:55   

is there a way to include a text field in a typedlist and return distinct entries without having to filter them out manually?

You want to have distinct rows having text/image or blob fields, as far as I know, you can't do this. Try it out in SQL code, if you succeed to have what you want post the query here so we can help you formulate it with LLBLGen Pro.

I was thinking that there may be a way to define the typedlist field by including a cast.

I don't understand this querstion.

chrishilton avatar
Posts: 49
Joined: 26-Jun-2007
# Posted on: 04-Oct-2007 15:27:07   

This query will execute successfully with my text column cast as nvarchar:

SELECT DISTINCT CAST([DESCRIPTION] AS NVARCHAR(MAX)) FROM DBO.[ACTIVITY]

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Oct-2007 15:50:13   

CAST is supported in DBFunction calls in v.2.5 The mentioned query can be formulated using a dynamicList. With the DESCRIPTION field's ExpressionToApply set to a DBFunctionCall to output the CAST part.

Please consult the LLBLGen Pro v.2.5 manual: "Using the generated code -> Calling a database function"

chrishilton avatar
Posts: 49
Joined: 26-Jun-2007
# Posted on: 04-Oct-2007 17:02:18   

Thanks for the swift response Walaa I'll have a look at that.

Just another (hopefully) quick question based on that approach. If I kept my TypedList defined in the designer, when I retrieve the IEntityFields2 collection (eg. activityTypedList.GetFieldsInfo()) is there a way to tell from the contained EntityField2 objects which have a SqlDbType of text?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 05-Oct-2007 12:04:49   

This info is stored in the FieldPersistenceInfo class.

using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    IFieldPersistenceInfo fieldInfo = adapter.GetFieldInfo(yourEntityField);
    Console.WriteLine("Datadase field type = {0}", fieldInfo.SourceColumnDbType);
}
chrishilton avatar
Posts: 49
Joined: 26-Jun-2007
# Posted on: 08-Oct-2007 11:46:24   

Thanks Walaa that works a treat and I just needed to add the following method to my partial DataAccessAdapter class:


public IFieldPersistenceInfo GetFieldInfo(IEntityField2 field)
{
    return base.GetFieldPersistenceInfo(field);
}