Adding DBFunction Calls to View/ Entity dynamically

Posts   
 
    
Posts: 72
Joined: 11-Aug-2006
# Posted on: 18-Sep-2006 07:01:28   

Hi There

I'm reasonably new to LLBLGenPro , but I am having a few issues figuring out the best way to do this.

I Have en Entity Called SKU which has relationships to Product and then Category ( standard shopping cart stuff )

I want to add 2 database functions to this entity while keeping the relationships with the other tables. I know how to add the DBfunctioncalls , but I am trying to figure the best way to do this seeing as it is a frequently used query ( i.e. building query from scratch every time would have quite a significant overhead I would imagine ) .

So maybe I would put the DBfunctioncall in the subclasses somewhere? The catch is I need to set the RoleName ( which is represented as 'public' below ) dynamically every time. Or maybe the best way is to define a typed list and use .expand & .add ?

The SQL would be something like ...

SELECT SKU.ID, SKU.Code , ... [more SKU.fields], dbo.BasePrice('Public', SkuID ) dbo.DoesSkuHaveDiscount('Public', SkuID ) From SKU

Thanks for your time! Martin****

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Sep-2006 07:11:06   

The catch is I need to set the RoleName ( which is represented as 'public' below ) dynamically every time. Or maybe the best way is to define a typed list and use .expand & .add ?

Sorry I didn't get this part of your question. Would you please explain further. And what exactly do you want these DBFunctions do?

Posts: 72
Joined: 11-Aug-2006
# Posted on: 18-Sep-2006 12:10:12   

Walaa wrote:

The catch is I need to set the RoleName ( which is represented as 'public' below ) dynamically every time. Or maybe the best way is to define a typed list and use .expand & .add ?

Sorry I didn't get this part of your question. Would you please explain further. And what exactly do you want these DBFunctions do?

They are custom SQL functions that return single values - bit for one and money for the other.

Sorry - so they are 2 seperate functions ( I have put a comma between them now ) - I just need to be able to represent the SQL below and put the 'Public' value in when constructing it.

SELECT SKU.ID, SKU.Code , ... [more SKU.fields], dbo.BasePrice('Public', SkuID ) , dbo.DoesSkuHaveDiscount('Public', SkuID ) From SKU

Thanks Marty

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 18-Sep-2006 21:14:27   

I think a typed list scenario for your problem corresponds pretty much to what's in the manual, so no surprise that way.

I don't think the generation of the query is much of an overhead, since persistence info are kept in a singleton, and all the rest should be faster than entity fetching.

Now, you may try to update your entity and corresponding factories (entity, fields, field) with custom fields associated with the corresponding dbfunction expression, but IMHO it's much work that you may not need.

Cheers

Posts: 72
Joined: 11-Aug-2006
# Posted on: 19-Sep-2006 00:58:54   

Jessynoo wrote:

I think a typed list scenario for your problem corresponds pretty much to what's in the manual, so no surprise that way.

I don't think the generation of the query is much of an overhead, since persistence info are kept in a singleton, and all the rest should be faster than entity fetching.

Now, you may try to update your entity and corresponding factories (entity, fields, field) with custom fields associated with the corresponding dbfunction expression, but IMHO it's much work that you may not need.

Cheers

The only issue with that is that I can't see how to relate the typed list back to the other entities?? confused In the application , this has 3 related tables that display information in different places on the page.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Sep-2006 08:18:46   

The only issue with that is that I can't see how to relate the typed list back to the other entities??

You may use a Dynamic List to fetch your fields with the appropriate DBFunction callings. You may also include fields from other related entities in your Dynamic List. Please refer to the manual: "Using the generated code -> Adapter/SelfServicing -> Using dynamic lists"

Also you may fetch the Dynamic List into dataReader and project it back to an EntityCollection. Please refer to the manual: "Using the generated code -> Adapter/SelfServicing -> Fetching DataReaders and projections"

Posts: 72
Joined: 11-Aug-2006
# Posted on: 21-Sep-2006 05:51:15   

Walaa wrote:

The only issue with that is that I can't see how to relate the typed list back to the other entities??

You may use a Dynamic List to fetch your fields with the appropriate DBFunction callings. You may also include fields from other related entities in your Dynamic List. Please refer to the manual: "Using the generated code -> Adapter/SelfServicing -> Using dynamic lists"

Also you may fetch the Dynamic List into dataReader and project it back to an EntityCollection. Please refer to the manual: "Using the generated code -> Adapter/SelfServicing -> Fetching DataReaders and projections"

Yes the problem is that it's not really a list as such.. it is a heirarchical set of data about 4 levels deep i.e. Product >> Category >> SKU >> SkuBasePrice

[SOLVED] - well sort of. I am having some sync problems now.

I realised that the parameter I wanted to use for the function was in another table, so I just put that whole area of data into a database view, including the function. and then I filter on the function. Sweet simple_smile