new entityfield in resultsetfields

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 28-Mar-2011 19:17:48   

Hi, is it possible to insert add a new constant fields into resultsetfields.

right now resultsetfields has 4 fields that are the combination of fields from several tables. i want to add a new field in there with the name Count and static value 10.

is it possible? thanks

-shane

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Mar-2011 04:23:50   

Hi shane,

I see it unnecessary as you can add that column later. For instance after fetch the DataTable. Anyway I think you may try to use an EntityField and set its ExpressionToApply property to a DBFunctionCall which sets this value at the database side. Then use that field in the fields.DefineField method to add the new field.

David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 29-Mar-2011 04:43:10   

daelmo wrote:

Hi shane,

I see it unnecessary as you can add that column later. For instance after fetch the DataTable. Anyway I think you may try to use an EntityField and set its ExpressionToApply property to a DBFunctionCall which sets this value at the database side. Then use that field in the fields.DefineField method to add the new field.

thats right i can but i have to loop through the generated datatable to add the new column. i was hoping maybe theres an easier way to it. thanks thou

-shane

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 29-Mar-2011 10:13:25   

I think you are talking about a TypedList, correct?

You can capture the fields defined in the TypedList into a new DynamicList, and thus you can easily add another fields. And fetch these into a new DataTable. Using the FetchTypedList() overloads that accepts a dataTable and a resultsetFields parameters.

The following is copied from the docs:

If you're using one of the FetchTypedList overloads of DataAccessAdapter which accepts IEntityFields2 and an IRelationPredicateBucket, you have to pass the object you get from typedlist.GetFieldsInfo() as the fieldCollectionToFetch value and the object you get from typedlist.GetRelationInfo() as the filterBucket parameter.

e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 29-Mar-2011 19:41:20   

Walaa wrote:

I think you are talking about a TypedList, correct?

You can capture the fields defined in the TypedList into a new DynamicList, and thus you can easily add another fields. And fetch these into a new DataTable. Using the FetchTypedList() overloads that accepts a dataTable and a resultsetFields parameters.

The following is copied from the docs:

If you're using one of the FetchTypedList overloads of DataAccessAdapter which accepts IEntityFields2 and an IRelationPredicateBucket, you have to pass the object you get from typedlist.GetFieldsInfo() as the fieldCollectionToFetch value and the object you get from typedlist.GetRelationInfo() as the filterBucket parameter.

no its not a typed list. i do create the fields in runtime using resultsetfields.

i was just thinking there's gotta be an easy way to add a new dummy field with a static value instead of looping through the generated datatable.

something like: fields.add(dummyfield, dummyvalue, index)

-shane

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 29-Mar-2011 21:01:42   

Sorry, I'm still not entirly sure what you are trying to do, and if you are using Typed Lists, Dynamic Lists, or Entities...?

Please could you post a sample of the code that you are using - it might give us a better idea of how to help you.

Thanks

Matt

e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 29-Mar-2011 21:29:42   

MTrinder wrote:

Sorry, I'm still not entirly sure what you are trying to do, and if you are using Typed Lists, Dynamic Lists, or Entities...?

Please could you post a sample of the code that you are using - it might give us a better idea of how to help you.

Thanks

Matt

it is a dynamic list. say it has five fields: entity1.field1, entity2.field2, entity2.field3, entity3.field4, entity3.field5 i want to add one more field into this resultset, say field6 with a staticValue.

so the generated datatable will have the fields from field1 through field6, first five coming from several entities and the final will be a static value.

generated sql will be something like:

select entity1.field1, entity2.field2, entity2.field3, entity3.field4, entity3.field5, staticValue as field6 .....

hope its better this time.

-shane

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 29-Mar-2011 22:33:07   

Much clearer, thanks. You can use FieldExpressions http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_expressionsaggregates.htm#expressions to achieve this - although they are designed for calculating values based on fields in the query, if you also combine their use with a DBFunction http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_dbfunctioncall.htm call to effectivly generate the SQL to return a static value.

Hope this helps

Matt

e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 29-Mar-2011 23:35:04   

MTrinder wrote:

Much clearer, thanks. You can use FieldExpressions http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_expressionsaggregates.htm#expressions to achieve this - although they are designed for calculating values based on fields in the query, if you also combine their use with a DBFunction http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_dbfunctioncall.htm call to effectivly generate the SQL to return a static value.

Hope this helps

Matt

Matt, thanks for the reply. I know i can use fieldexpressions and i ve tried many combinations of it but couldnt get it to work. Maybe a code snippet?

thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Mar-2011 05:10:21   

Shane, here is the example snippet:

ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(EmployeeFields.FirstName, 0);
fields.DefineField(EmployeeFields.LastName, 1);

// this is the constant trick
fields.DefineField(new EntityField("ConstantX", new Expression("X", ExOp.None, new Expression())), 2);
// you can use it for other types as well:
// fields.DefineField(new EntityField("ConstantN", new Expression(10, ExOp.None, new Expression())), 2);

// fetch
DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, null, true, null, null, 0, 0);
David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 30-Mar-2011 16:57:09   

daelmo wrote:

Shane, here is the example snippet:

ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(EmployeeFields.FirstName, 0);
fields.DefineField(EmployeeFields.LastName, 1);

// this is the constant trick
fields.DefineField(new EntityField("ConstantX", new Expression("X", ExOp.None, new Expression())), 2);
// you can use it for other types as well:
// fields.DefineField(new EntityField("ConstantN", new Expression(10, ExOp.None, new Expression())), 2);

// fetch
DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, null, true, null, null, 0, 0);

thank you thats exactly what i needed.