Obtaining a SQL/parameter values without executing it
Obtaining a SQL/parameter values without executing it
In LinqConnect, is there a way to obtain a SQL with all the parameter values without executing it?
Re: Obtaining a SQL/parameter values without executing it
2 Scenarios:
1) IQueryable<T> to SQL + parameter values
2) a way to get a SQL for Min/Max(IQueryable<T> => int)
1) IQueryable<T> to SQL + parameter values
2) a way to get a SQL for Min/Max(IQueryable<T> => int)
Re: Obtaining a SQL/parameter values without executing it
Unfortunately, there is no way to do that with a current implementation.
Re: Obtaining a SQL/parameter values without executing it
would it be possible to implement this functionality in the future?
Re: Obtaining a SQL/parameter values without executing it
We are processing your request.
Re: Obtaining a SQL/parameter values without executing it
Please try this workaround:
Code: Select all
using System;
using System.IO;
using System.Text;
using MyContext;
namespace MyConsoleApp
{
class Program
{
static void Main(string[] args)
{
using (var context = new MyDataContext())
{
var log = new MyTextWriter();
context.Log = log;
string name = "abcd";
var dept = new DEPT() { DEPTNO = 6, DNAME = name };
context.DEPTs.InsertOnSubmit(dept);
try
{
context.SubmitChanges();
}
catch (Exception e)
{
if (e.Message != "Getting SQL without execution")
throw e;
}
Console.WriteLine(log.GetSql());
Console.ReadKey();
}
}
}
public class MyTextWriter : TextWriter
{
StringBuilder SQL;
public MyTextWriter()
{
SQL = new StringBuilder();
}
public override void Write(string value)
{
SQL.Append(value);
}
public override void WriteLine(string value)
{
SQL.AppendLine(value);
}
public override void WriteLine()
{
throw new Exception("Getting SQL without execution");
}
public override Encoding Encoding {
get { return Encoding.Default; }
}
public string GetSql()
{
string query = SQL.ToString();
SQL.Clear();
return query;
}
}
}
Re: Obtaining a SQL/parameter values without executing it
*without executing it*
Re: Obtaining a SQL/parameter values without executing it
The code doesn't send any CUD statements to the server.