Reputation: 1068
I have 2 tables as follows :
CatTable
DogTable
So I would like to write down a query where return me the list of all data present in the table CatTable PLUS if in the Table DogTable the value in the field “CatCode” is the same of CatTable.CatCode and the field “NameCode” is Empty then should return a value "false" in the field “DogTable.CatCode”
Example
var query = from c in CatTable
from d in DogTable
where c.CatCode == d.CatCode
select new { c.CatCode, c.CatName, d.CatCode }
Do you have any suggestion about that?
Upvotes: 0
Views: 59
Reputation: 4440
a simple version is to use the Any
to return the boolean of the logic you want on that last field
var query = CatTable.Select(ct => new
{
CatCode = ct.CatCode,
CatName = ct.CatName,
DogCatCode = !DogTable.Any(dt => dt.CatCode == ct.CatCode && dt.NameCode == "")
});
Upvotes: 2