This is what I am trying to do.
DECLARE @condition bit
set @condition=1
-- Scenario one.
SELECT top 10 cpd.column1,cpd.column2,
CASE WHEN @condition=1 THEN crv.column1 ELSE '0' END
FROM Table1 cpd
LEFT JOIN Table2 crv
on cpd.column= crv.column
--Scenarion 2
DECLARE @condition bit
SET @condition=0
SELECT top 10 cpd.column1,cpd.column2,
CASE WHEN @condition=1 THEN crv.column1 ELSE '0' END
FROM Table1 cpd
--LEFT JOIN Table2 crv !! Based on the condtion I have to remove the join
--on cpd.column= crv.column
--Here I get the error crc.column1 that it cannot be bound.
I am trying to achieve this in LLBLGen Pro :
public void Test(bool condition)
{
IRelationPredicateBucket bucket = new RelationPredicateBucket();
if (condition)
{
bucket.Relations.Add(Entity1.Relations.Entity2UsingColumn);
}
var queryFactory = new QueryFactory();
var query = queryFactory.Table.From(bucket.Relations)
.Select(() => new DataContract()
{
Field1= Entity1Fields.Field1.ToValue<string>(),
//Fields2= Entity2.Fields1.ToValue<int>(), !! I get an error here the same as that of sql , a select that has no join in the query.
//To solve this I am trying to change my select using the ternary operator, but as it tries to evaluate because of 'ToValue<int>()' I get an error that column specified in slect does not have a relation in the from clause.
//As I have removed the join too
Field2= condition ? Entity2.Field1.ToValue<int>()
:0
}); ;
}
Is there any way to achieve this?