4 ms·
Is LINQ actually an ORM? It looks like a DSL to do relational stuff in C#, but I don't see where the 'O' part of ORM fits in especially not in your examples to
by eru 9y ago
Is LINQ actually an ORM? It looks like a DSL to do relational stuff in C#, but I don't see where the 'O' part of ORM fits in especially not in your examples to show off LINQ's power and convenience.
- jeswin 9y agoLINQ is not an ORM. My examples were showing easy, lazy evaluation. My C# is rusty, but the examples mostly hold I think. The following gets executed on iteration (of expensiveOrders), the lambda is compiled into a Function and run on each item in orders: IEnumerable<T> orders = ...; const expensiveOrders = orders.Where(o => o.total > 100) The following gets compiled into an expression tree, which an ORM can analyze and convert to SQL. Basically it's just "Code as Data". IQueryable<T> orders = ...; const expensiveOrders = orders.Where(o => o.total > 100) The language's ability to treat code as data allows the programmer to express queries in native language syntax and pass it to an ORM (such as EF or Linq to Sql) for execution on a data store. Add: Where does the 'O' part fit in? You build a entities (in plain C#) with relationships to each other, and you could do stuff like: //Pseudo-code db.Customers.Where(c => ...) db.Save(customer); Edit: clarified - executed on iteration, not immediately.
- deleted 9y ago[deleted]
- eru 9y agoThanks. My quip was just that objects (as in object-oriented-programming) aren't the right abstraction. Having some kind of mapper in your language between the database and the entities your program is dealing with is useful, and you showed that functional programming is a more friendly host than oop. (Logic programming might also be workable?)
- int_19h 9y agoObjects are fine, it's classes that are often limiting. Consider the very first example above (corrected to be valid): var r = customers.Select(c => new { cust = c, orders = c.Orders }) This gives you an IEnumerable (basically, a forward-only sequence) of objects - but these objects are of an anonymous type that was implicitly defined by "new".
- eecc 9y agoLinq looks like a free monad: you declare the program as a data structure and the runtime implementation just interprets it on the go (something you could - not so easily - try to do with a strategy pattern)
- Merad 9y agoLINQ itself doesn't have anything directly to do with SQL. It's a mechanism for composing expression trees that are compiled into your application. At runtime a LINQ query provider can walk the expression tree and translate it into a query for the underlying data store. It's a very very powerful concept, but IME it doesn't get used all that much for things other than SQL because writing a query provider is a lot of work. Anyway, the typical C# ORM is Entity Framework, which includes the LINQ-to-Entities query provider.
- scarface74 9y agoThe Mongo Linq provider is excellent.
- deleted 9y ago[deleted]