it's hard to answer the question because linq is so many different things. for instance, sticking to c#, the following things are involved:
- query expressions are "pre-processed" into "c# without query expressions" which is then compiled normally. the query expression part of the spec is really short - it's basically a mechanical translation which doesn't assume anything about the real meaning of the query, beyond "order by is translated into orderby/thenby/etc".
- delegates are used to represent arbitrary actions with a particular signature, as executable code.
- expression trees are used to represent the same thing, but as data (which can be examined and translated into a different form, e.g. sql)
- lambda expressions are used to convert source code into either delegates or expression trees.
- extension methods are used by most linq providers to chain together static method calls. this allows a simple interface (e.g.
ienumerable<t>) to effectively gain a lot more power.
- anonymous types are used for projections - where you have some disparate collection of data, and you want bits of each of the aspects of that data, an anonymous type allows you to gather them together.
- implicitly typed local variables (
var) are used primarily when working with anonymous types, to maintain a statically typed language where you may not be able to "speak" the name of the type explicitly.
- iterator blocks are usually used to implement in-process querying, e.g. for linq to objects.
- type inference is used to make the whole thing a lot smoother - there are a lot of generic methods in linq, and without type inference it would be really painful.
- code generation is used to turn a model (e.g. dbml) into code
- partial types are used to provide extensibility to generated code
- attributes are used to provide metadata to linq providers
obviously a lot of these aren't only used by linq, but different linq technologies will depend on them.
if you can give more indication of what aspects you're interested in, we may be able to provide more detail.
if you're interested in effectively implementing linq to objects, you might be interested in a talk i gave at ddd in reading a couple of weeks ago - basically implementing as much of linq to objects as possible in an hour. we were far from complete by the end of it, but it should give a pretty good idea of the kind of thing you need to do (and buffering/streaming, iterator blocks, query expression translation etc). the videos aren't up yet (and i haven't put the code up for download yet) but if you're interested, drop me a mail at firstname.lastname@example.org and i'll let you know when they're up. (i'll probably blog about it too.)
matt warren's blog has all the answers (and a sample iqueryable provider implementation to give you a headstart):
read this article:
perhaps my linq for r6rs scheme will provide some insights.
it is 100% semantically, and almost 100% syntactically the same as linq, with the noted exception of additional sort parameters using 'then' instead of ','.
- only dealing with lists, no query providers.
- not lazy, but eager comprehension.
- no static types, as scheme does not use them.
my implementation depends on a few core procedures:
- map - used for 'select'
- filter - used for 'where'
- flatten - used for 'selectmany'
- sort - a multi-key sorting procedure
- groupby - for grouping constructs
the rest of the structure is all built up using a macro.
bindings are stored in a list that is tagged with bound identifiers to ensure hygiene. the binding are extracted and rebound locally where ever an expression occurs.
i did track the progress on my blog, that may provide some insight to possible issues.
for design ideas, take a look at c omega, the research project that birthed linq. linq is a more pragmatic or watered down version of c omega, depending on your perspective.
mono (partially?) implements linq, and is opensource. maybe you could look into their implementation?
- How does Linq work (behind the scenes)?
- How does linq actually execute the code to retrieve data from the data source?
- How does OrderBy in LINQ work (behind the scenes)?
- How does coding with LINQ work? What happens behind the scenes?
- How does linq concat work under the hood?
- How does a LINQ IEnumerable work under the hood?
- How does the .All(db1 => db1.Text != wb.Text)) in LINQ work when comparing two lists?
- How does LINQ work when it should affect the previous calls in the chain? (e.g. mongo/Linq2Sql)
- How does the following LINQ statement work?
- How does LINQPad reference other classes, e.g. Books in the LINQ in Action samples
- How does LINQ expression syntax work with Include() for eager loading
- Why does the Linq Cast<> helper not work with the implicit cast operator?
- how does except method work in linq
- How does the LINQ RefreshMode work?
- How does linq Last() determine the last item?
- How does the default comparator work in C#?
- Does this LINQ code perform multiple lookups on the original data?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- how does one compare the date part of a nullable datetime in a linq / lambda query?
- Large LINQ Grouping query, what's happening behind the scenes
- Linq OrderBy does not sort a List<T>. How do I sort the list?
- How does this linq code that splits a sequence work?
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- How can I write the following code more elegantly using LINQ query syntax?
- How does linq Expression<TDelegate> assignment work on a language syntax level
- How to code the partial extensions that Linq to SQL autogenerates?
- Why does the StringComparison.InvariantCultureIgnoreCase not work with this Db4o linq query?
- How does the CLR interpret the following LINQ query
- How to work around the fact that Linq to SQL is using separate SQL DELETE statements for each item in DeleteAllOnSubmit
- How does this RavenDB linq query work
More Query from same tag
- LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)', store expressions
- Is possible keep the properties type after using linq selection?
- Processing ranking data w/ C# & LINQ
- Building hierarchy model C#
- Expression Tree 'Any' on Collection
- Convert IEnumerable<int> to int
- LINQ Database
- Get list of child records
- LINQ to SQL: Multiple / Single .dbml per project?
- Merge 2 lists of 2 different types (alternatives)
- Fixing Loop Reference in Entity Framework Code First when Serializing to Json
- LINQ Conditional Sum
- Linq to XML, retrieving list from like names elements
- Does LINQ's ExecuteCommand provide protection from SQL injection attacks?
- does linq where call reduce calls to my database (Custom built)
- How to use Date function in LINQ to entities?
- SQL Trigger is trying to insert a null value but my C# code is passing int 300?
- How can I perform OrderBy using LINQ on XML data?
- LINQ IsAssignableFrom check between two Type?
- Multi column data transformation
- Dynamically building an expression tree
- How to search in a list whether a list of given items exists in the same order
- Group or sort list/array by number of matching keywords
- c# Replace string in a property of a class using linq not working
- How to query all tables that implement an interface
- LINQ ile Array Splitting
- Fastest way to assign item from a list to another item in a list
- Saved projection expression for re-use in different linq expressions with two source objects
- EF Core ToDictionary throw expression could not be translated
- How to merge two lists based on a property?