I feel like it would be as simple as this:
yourDbContext.COESDetails.Where(detail => detail.COESDetailsCOESDefects.Any()).ToList();
Correct me if I'm wrong.
Question
Just wondering how to write the following SQL in LINQ syntax
select * from COESDetails
where COESNo in
(select distinct COESNo from COESDefects)
either Fluent or Query Expression, or Both
COESDefects
have a navigation property to COESDetails
public class COESDefects
{
public int Id { get; set; }
public int COESNo { get; set; }
public string Comments { get; set; }
public virtual COESDetails COESDetails { get; set; }
}
public class COESDetails
{
public COESDetails()
{
COESDetailsCOESDefects = new List<COESDefects>();
}
public int COESNo { get; set; }
public int Postcode { get; set; }
public virtual ICollection<COESDefects> COESDetailsCOESDefects { get; set; }
}
Thanks
La solution 2
I feel like it would be as simple as this:
yourDbContext.COESDetails.Where(detail => detail.COESDetailsCOESDefects.Any()).ToList();
Correct me if I'm wrong.
Autres conseils
Try this:
var query =
from x in context.COESDetails
join y in context.COESDefects on x.COESNo equals y.COESNo into ys
where ys.Any()
select x;
Sometimes, if the query is complex, it's easier to just execute it directly e.g.
IEnumerable<COESDetails> myResults = dbConext.ExecuteQuery<CCOESDetails>("select * from COESDetails where COESNo in (select distinct COESNo from COESDefects)")