Collection with entites based on different queries

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 10-Jun-2005 23:30:48   

Hi,

I want to know how to do the following if it's possible:

If I have a machine with counters. These counters will be reported often and stored in the database. Now I need a grid to show all the last counter readings of these machines. Now here's the tricky part. My SP I have at the moment is using some GROUP BY, SELECT IN etc. which somehow I know I will be able to convert to code using the DQE. But now I also have something like this:

ISNULL(MAX(table1.COUNTER - ((CAST(SUBSTRING('999999999',1,CAST(table2.number_of_ciphers AS int)) AS numeric(9)) + 1) * (table1.reading_lap -1))),0) COUNTER

ISNULL and CASTS are not supported. Should I just give up and keep on using this stored procedure to fill a collection of entities or should I try to write code to figure this out? The application should work for different databases, that means different stored procedures, which means more maintenance. That's way we want to get rid of most stored procedures, but hey, some very tricky stuff is being done by those...

UNIONS are not supported either. How is it possible for me to use two kinds of queries to fill one collection of the same type of entities? (Like a workaround for this).

One other thing: LLBLGen use mapping from tables to entities. I am used to use entities with data from multiple tables and then store data in a single table. It seems like i have to change my thinking a lot and change to using multiple objects with relations to fill the data of one entity and update the table I think.....right?

Gr.,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 11-Jun-2005 12:45:41   

G.I. wrote:

Hi,

I want to know how to do the following if it's possible:

If I have a machine with counters. These counters will be reported often and stored in the database. Now I need a grid to show all the last counter readings of these machines. Now here's the tricky part. My SP I have at the moment is using some GROUP BY, SELECT IN etc. which somehow I know I will be able to convert to code using the DQE. But now I also have something like this:

ISNULL(MAX(table1.COUNTER - ((CAST(SUBSTRING('999999999',1,CAST(table2.number_of_ciphers AS int)) AS numeric(9)) + 1) * (table1.reading_lap -1))),0) COUNTER

ISNULL and CASTS are not supported. Should I just give up and keep on using this stored procedure to fill a collection of entities or should I try to write code to figure this out? The application should work for different databases, that means different stored procedures, which means more maintenance. That's way we want to get rid of most stored procedures, but hey, some very tricky stuff is being done by those...

Those things aren't supported (ISNULL and CAST). What you can do is create an IPredicate implementation (derive from the Predicate class) which allows you to emit this string directly into the query. Though it then still isn't cross platform, though these things probably never will be (SUBSTRING... CAST, ISNULL...)

UNIONS are not supported either. How is it possible for me to use two kinds of queries to fill one collection of the same type of entities? (Like a workaround for this).

Just fill the same connection with the second query. New entities not in the collection will be added to it. Entities you've already fetched into the collection will be ignored. If you;re using SelfServicing, please set entitycollection.SuppressClearInGetMulti to true before calling GetMulti

One other thing: LLBLGen use mapping from tables to entities. I am used to use entities with data from multiple tables and then store data in a single table. It seems like i have to change my thinking a lot and change to using multiple objects with relations to fill the data of one entity and update the table I think.....right?

Yes, though this will be addressed soon with support of inheritance, i.e. supertype/subtype entities, which means entities which are subtypes of other entities can thus be spread over multiple tables.

Frans Bouma | Lead developer LLBLGen Pro
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 11-Jun-2005 20:19:55   

Ok...Predicate class is something I will take a closer look at. I can always place the SQL strings in resource files or any other xml file, and based on a setting in the app.config get the right SQL string for the type of database.

Thanks for the tip for when using selfservicing...somehow I overlooked that...and I am looking forward to the new release, that inheritance (saw your post in the announcements) is going to be very useful in the future for us!

Gr.,

G.I.