3 ms·
One thing I really like is using Entity Framework inside of LINQPad (C#) for ad-hoc sysadmin-style queries. They are much, much easier to write; and because mo
by gwbas1c 3y ago
One thing I really like is using Entity Framework inside of LINQPad (C#) for ad-hoc sysadmin-style queries.
They are much, much easier to write; and because most sysadmin-style queries aren't performance bound, it hits a great sweet spot where the ergonomics of an ORM are a win.
I'd really like a universal ORM, though. I'd like to be able to write queries in a SQL-like language and have my classes automatically generated for me, no matter what programming language I'm using. I'd like to write joins in a SQL-like language and have the data structures automatically populated, no matter what programming language I'm using.
I think this exposes the real flaw in ORMs and SQL: ORMs are too tied to the programming language, and SQL is too tied to its own domain. For example, if I could write a set of joins that returned structured JSON, and a JSON schema, perhaps some of the ORMs could be replaced by a simple JSON parser?
- 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();