score:2
Everything is possible, it just requires a truckload of work. The problem is that you first have to parse the SQL query, and interpret the AST to convert it into a linq expression tree. This isn't trivial, as Linq isn't 1:1 compatible with sql: for example, in linq, aggregates on a groupby are external to the groupby, while in SQL they're internal: they have to be in the same scope as the groupby otherwise they won't work. This kind of info is needed for converting linq queries into SQL queries but also the other way around.
So to store queries, I'd chose a different route, e.g. a specification pattern
score:1
I don't believe there's anything built into LINQ-to-SQL.
In theory I dare say it would be possible (although it wouldn't guarantee roundtripping, as there are different ways of expressing the same query) - but very hard to do well.
score:0
Thing what can possibly help you - LINQPad. I suppose, it can't translate SQL to LINQ query, but it can translate LINQ to SQL.
One option would be to track from SQL generated IL code. For example:
SELECT TOP (50) [t0].[Id], [t0].[tralala]
FROM [pamparam] AS [t0]
Generates:
IL_0001: ldarg.0
IL_0002: call LINQPad.User.TypedDataContext.get_pamparam
IL_0007: ldc.i4.s 32
IL_0009: call System.Linq.Queryable.Take
IL_000E: call LINQPad.Extensions.Dump
This way it's quite obvious, that LINQ query would look like:
pamparam.Take (50)
Source: stackoverflow.com
Related Articles
- Convert SQL Query back to Linq Expression programmatically
- Convert Method to Linq Expression for query
- Convert linq query expression with multiple froms into extension method syntax
- Convert this Linq query from query syntax to lambda expression
- Convert lambda expression to linq query
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- convert linq to object query to sql query (no linq to sql code or datacontext)
- Convert Linq Query Expression to Method Syntax equivalent
- Cannot implicitly convert type System.Collections.Generic.List back to Object after linq query
- How to convert this LEFT JOIN Linq Query to Lambda expression
- Unreachable expression code in LINQ query
- Convert linq query to lambda expression
- Convert LINQ query to string, send to remote server to parse into an expression using Roslyn?
- How can I convert Linq to Entities Query into expression tree?
- How do I convert this LINQ query expression from C# to VB.NET?
- Linq convert a Method Syntax to Query Expression
- How to Convert this Linq Query into Lambda Expression
- Convert linq expression from method syntax to query syntax
- A LINQ question: map query expression to c# code
- Convert this linq code to expression
- How to convert this SQL query to LINQ or Lambda expression in C#?
- Convert this SQL Query to a Linq Lambda Expression
- How to convert a LINQ query back to simple foreach?
- Convert SQL update query to c# LINQ code
- How to convert this LINQ Query result back to DataTable object?
- Convert LINQ query expression
- Convert SQL query into Linq expression
- how to convert linq query into lambda expression
- How to convert linq query to lambda expression
- How to Convert Method Based query to Query Expression in Linq
- How to query xsi:type from an attribute using Linq to XML?
- Using cross-join / pivot with Linq
- get indexes of different elements from arrays with equal length using Linq
- Databinding LINQ query results (with join tables) to DataGrid
- LINQ: get nested arrays based on a groupby?
- Group by results which are in the same order
- How to convert a linq query to ToList() to use extended properties
- linq expression cannot contain lamba expressions exception
- What is the LINQ equivalent to MIN?
- Linq to Entities custom ordering via position mapping table
- String comparison inside a LINQ query results in a nullable booelan?
- LINQ multiple where clause
- How to put LINQ condition on partial view used by all the views in razor MVC project?
- linq to sql Association problem with foreign keys
- Filter the "Includes" table on Entity Framework query
- Return List<object> from IEnumerable C#
- LINQ to transform array [x0,y0, ..., xN, yN] into enumerable [p0, ..., pN]
- System.Linq to String issue with GET request
- LINQ How to return common objects across multiple lists
- Convert XML to C# Dictionary