Constant in ResultsetFields

Posts   
 
    
jaskey avatar
jaskey
User
Posts: 23
Joined: 09-Jul-2006
# Posted on: 16-Sep-2006 06:43:06   

Im trying to generate several ResultsetFields objects and then combine the datatables into one for search results that can return multiple entities.... like cars and beer for instance...

Car: CarId CarName static-1 Beer:BeerId BeerName static-2

1234 Toyota 1 1235 Honda 1 12 Moosehead 2 23 FatTire 2

Now I can return mixed results but adjust the hyperlink accordingly based on 'type' to point to the correct .aspx page for that object

car.aspx?id=1234 beer.aspx?id=12

How can I add a static column in a ResultsetFields...

fields.add(?)

I didn't see this in the docs, is there a more appropriate way to do this?

thanks

j

PS - Cars and Beer are still legal in Wyoming

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 17-Sep-2006 00:00:50   

jaskey wrote:

Im trying to generate several ResultsetFields objects and then combine the datatables into one for search results that can return multiple entities

This is a union query, which isn't supported in LLBLGen, at least not directly. Unions are always read-only because you are presenting more than one entity in the same list, as though it is one. If they are indeed one "thing" with some common and some differing attributes, you should consider using a supertype-subtype approach. Look in the documentation at "Concepts - Entity inheritance and relational models".

If you want to keep your relational db model as is, you'll need to do a workaround that uses UNION queries or some ADO.NET trick to do the same thing after you perform 2 fetches. There are many ways to do this. Do a search on "UNION" in the forums and you'll see many threads that cover this.

Here's one simple workaround though:

Create a view in your database that does the union query:


select
   'ID' = CarId,
   'Name' = CarName,
   'Type' = 1
from Car
union select
   'ID' = BeerId,
   'Name' = BeerName,
   'Type' = 2
from Beer

Then create a TypedView that is mapped to this view. See "Generated code - Using the typed view classes" in the documentation.

Hope this helps.