3 ms·
LINQ 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 iterat
by jeswin 9y ago
LINQ 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)