by kkoste · 3y ago · 0 comments
You can do this using Entity Framework Core.
var query = from obj in context.Objects
join objChild in context.ObjectChildren on obj.id equals objChild.ObjId
where obj.Name = "SomeName"
select new {obj, objChild}
var res = await query.ToListAsync()
This will give you a list of anonymous objects. But you can also just have the query create non-anonymous objects. var res = context.Objects.Include(x=> x.ChildObjects)
But if you have to do joins then definitely query syntax is much clearer. For example the join above in lambda syntax looks like this: var query = await context.Objects
.Join(context.ObjectChildren,
obj => obj.Id,
objChild => objChild.ObjId,
(obj, objChild) => new { Obj = obj, ObjChild = objChild })
.Where(objAndObjChild => objAndObjChild.Obj.Name == "SomeName")
.ToListAsync();