I wish to select only the first record from the 'CustomerSubOwners
' table in join query below and wondered what was the best way to achieve this in LINQ.
var result= (from t1 in db.Cases
from t2 in db.CustomerSubOwners
.Where(o => t1.CustomerId == o.CustomerId && o.Expiry >= DateTime.Now)
.DefaultIfEmpty()
select t1);
I think you are looking for the Take method like so:
var result= (from t1 in db.Cases
from t2 in db.CustomerSubOwners.Where(o => t1.CustomerId == o.CustomerId && o.Expiry >= DateTime.Now)
.Take(1)
.DefaultIfEmpty()
select t1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With