Hi,
I have a problem, I can't find a solution for. I've searched the forums, but I couldn't find a topic that matches my problem.
I'm using LLBLGen 1.0.2005.1 (latest builds of designer and runtimes), .NET 2.0 and VS 2005.
For explaining the problem I simplified this example:
I have two tables: "Cars" and "EnginesTypes". The table "EngineTypes" has a field called "CarID". I create two entities for those tables and a 1:n relation between "Cars" and "EngineTypes".
Now I want to fetch an EntityCollection. I want the fetch all cars, but for the cars with field "CarType" set to "SportsCar" I only want "EngineTypes" with field "Size" > 2.
LLBLGen will execute two queries. One on table "Cars" and one on table "EngineTypes". In the query for "EngineTypes" I want to add a condition on the field "CarType" in the table "Cars" which should compare the "CarType" of the "Car" which is being referred to by the "CarID".
This would be the SQL statement if it were done in one query with a join:
SELECT * FROM Cars LEFT JOIN EngineTypes ON Cars.ID = EngineTypes.CarID WHERE NOT Cars.CarType = "SportsCar" OR (EngineTypes.Size > 2 OR EngineTypes.Size IS NULL)
The last check on Size IS NULL is to make sure cars without EngineTypes are also selected.
When the EngineTypes are selected separately, the SQL would be something like this:
SELECT * FROM EngineTypes WHERE CarID = @CarID AND (NOT @CarType = "SportsCar" OR Size > 2)
I create an EntityCollection and a new RelationPredicateBucket. I want to add a PredicateExpression with on the field "CarType". But when I try to fetch it, I get an exception:
An exception was caught during the execution of a retrieval query: The column prefix 'dbo.Cars' does not match with a table name or alias name used in the query.
This is happening, because it is making an selection on EngineTypes and it should add a variable to the query, instead of an field-reference on a table that was queried before.
Anyone has a solution??
Thanks,
René