3 ms·
> I'd like to be able to write queries in a SQL-like language You can do this using Entity Framework Core. var query = from obj in context.Objects
by kkoste 3y ago
> I'd like to be able to write queries in a SQL-like language
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.
- shortrounddev2 3y agoPersonally I don't prefer the SQL syntax in Linq. I like using EF Core, but with regular C# style statements
- kkoste 3y agoI really think this depends on the situation. If you have an objet with foreign key relations to a lot of other objects then using lambda syntax is most likely preferred: 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();