Reputation: 114
i want to if control in linq query, but i dont know how can i do this control.
var result = from sk in stokKartlari
join ue in uretimEmirleri on sk.id equals ue.UrunId
join ub in urunBarkodlari on ue.Id equals ub.UretimEmriId
select new UretimEmriJsonViewModel
{
Id = ue.Id,
BaslangicTarihi = string.Format("{0:yyyy-MM-dd}", ue.BaslangicTarih),
BitisTarihi = string.Format("{0:yyyy-MM-dd}", ue.BitisTarih),
StokAdi = sk.stokadi,
StokKartiId = ue.UrunId,
UretimAdet = ue.Adet,
UretimBasTarih = string.Format("{0:yyyy-MM-dd}", ue.UretimBasTarih),
UretimBitTarih = string.Format("{0:yyyy-MM-dd}", ue.UretimTamamTarih),
UretimSeriNo = ue.UEmirBarkod,
Res= //true or false
};
I try to if urunBarkodlari.Where(x=>x.Printed==true && x.UId==ue.Id).Count()
count > 0 Res= true or false
I am doing what I want by returning the list with foreach and sending a query. Can I do this over linq without sending a query?
Upvotes: 0
Views: 59
Reputation: 114
I fixed my prob;
Res = urunBarkodlari.Any(x => x.Printed== true && x.UId==ue.Id).Count() > 0
Upvotes: 0
Reputation: 125
urunBarkodlari.Any(x => x.Printed== true && x.UId==ue.Id).Count() > 0
You dont need "? true : false " will return true if there are any records.
You can check this post: https://stackoverflow.com/questions/3703256/linq-extension-methods-any-vs-where-vs-exists#:~:text=Any()%20returns%20true%20if,the%20IList%20back%20before%20Linq.
Upvotes: 1