DIP 50 - AST macros
Regan Heath
regan at netmail.co.nz
Wed Nov 13 01:58:05 PST 2013
On Tue, 12 Nov 2013 14:38:43 -0000, John Colvin
<john.loughran.colvin at gmail.com> wrote:
> On Tuesday, 12 November 2013 at 13:50:49 UTC, Jacob Carlborg wrote:
>> auto person = Person.where(e => e.name == "John");
>>
>> Translates to:
>>
>> select * from person where name = 'John'
>>
>
> for those of us entirely unfamiliar with linq, what is this supposed to
> do? Select people with name "John" from a collection of people, like in
> sql? It seems trivial to do this using filter, or am I missing
> something...?
Linq is often confused with LinqToSQL, the above was a description of what
happens in the latter. If Person was an object representing a table from
a SQL database, then calling 'where' on it would translate into an
IQueryable<Person> object which when iterated upon using foreach would
execute the SQL statement shown above and return the resulting rows as
<someperson> objects one by one to the foreach body.
Pure Linq is a DSL, an alternate syntax, which looks a lot like SQL, which
can translate to SQL but is not limited to SQL. It could translate to any
alternate database syntax, or simply access a container supporting the
required operations.
The motivation is the same as for "foreach", it is a general syntax for
accessing a wide range of containers including databases with a common
syntax. We could, equally, go the other way, use the IMO nicer
composition syntax X.where(..).foo(...).etc and translate that to SQL,
without the need to the SQL like DSL inside D.
For some LINQ examples, see:
http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
For a specific where example using a simple container, see "Where - simple
1"
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list