FetchTypedList and TypeConverters

Posts   
 
    
cmayer
User
Posts: 4
Joined: 05-Sep-2011
# Posted on: 05-Sep-2011 10:18:57   

Hi folks,

LLBLGen Version: 3.1 Final (Adapter) DB: Firebird 2.1

i use FetchTypedList to query a C# DataTable with two columns. On the one hand there is a simple field in ResultsetFields (ItemFields.ID), on the other hand i use a DbFunctionCall to call "case when" integrated in Firebird.

DbFunctionCall funcStockUnderRun = new DbFunctionCall("case when ({0} < {1}) then 1 else 0 end", new object[] { ItemFields.Stock, ItemFields.MinStock });

The function returns 1 or 0 of type int if the statement is true or not. How can i add a TypeConversation, to get an bool column in the resulting DataTable ?

regards

Christian

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Sep-2011 10:59:47   

Since you are using a DBFunctionCall, why don't you return a bool from the database, instead of an int?

cmayer
User
Posts: 4
Joined: 05-Sep-2011
# Posted on: 05-Sep-2011 11:56:05   

Firebird unfortunately doesn't support the type bool. I have to use char in the Database and a TypeConverterToUse in the Entity.

In the case of FetchTypedList and ResultSetFields, i haven't found the possibility to add a TypeConverter. I tried to set the DataType in the Field.

EntityField2 fieldStockUnderRun = new EntityField2("StockUnderRun", funcStockUnderRun, AggregateFunction.None, typeof(bool));

But still no success.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Sep-2011 16:14:04   

You can try to process the returned dataTable, or project it to the structure that you need. For example you can add a new row to hold the bool value, and loop on rows to read the int value from one column and insert the boolean equivelant into the new column,

cmayer
User
Posts: 4
Joined: 05-Sep-2011
# Posted on: 05-Sep-2011 16:59:05   

Yes, creating a new column in the DataTable should work. I will give it a try.

Apart from that, is there a possibillity to set the TypeConverterToUse on a custom field created with

new EntityField2 (...);

?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Sep-2011 18:32:35   

You want to set it programatically, but TypeConverters are set at Design time.

cmayer
User
Posts: 4
Joined: 05-Sep-2011
# Posted on: 05-Sep-2011 18:45:14   

Ok then there is no way to do this, because i cant set TypeConverters at Design time for Fields which are created at runtime.

So i have to convert this manually. Thank you Walaa for clarifying this.