Here is my query.
var Result = (
from t1 in dbContext.Table1
join t2 in dbContext.Table2 on t1.Id equals t2.Id
join t3 in dbContext.Table3 on t1.Id equals t3.Id
where
&& t1.CategoryUId == Input.CategoryUId
select new CategoryInfo
{
Table1ID = t1.Id,
Table1Name = t1.Name,
TableTypeUid = t1.TypeUId,
ProductName = t2.ProductName,
BrandName = t3.BrandName
}
).ToList();
Here I wanted to add extra con in second line :-
join t2 in dbContext.Table2 on t1.Id equals t2.Id && t2.Active=true
But it is not taking, giving me error.
How to add that?
Can we add extra condition in second line.
Tried :
var Result = (
from t1 in dbContext.Table1
join t2 in dbContext.Table2 on t1.Id equals t2.Id
join t3 in dbContext.Table3 on t1.Id equals t3.Id
where
&& t1.CategoryUId == Input.CategoryUId
select new CategoryInfo
{
Table1ID = t1.Id,
Table1Name = t1.Name,
TableTypeUid = t1.TypeUId,
ProductName = t2.ProductName,
BrandName = t3.BrandName}).ToList();
Here I wanted to add extra con in second line :-
join t2 in dbContext.Table2 on t1.Id equals t2.Id && t2.Active=true
2
Answers
You can either do
which you should always do if you are doing a left-join using
DefaultIfEmpty
Or you can add it into the
where
Note that C# uses
==
not=
for comparison, and thatbool
does not need it anyway, you can just use the value directly.someBool == true
is the same assomeBool
, andsomeBool == false
is the same as!someBool
.Replace
join
withfrom
andWhere
condition. It is documented in Complex Query Operators