LINQ to SQL : New method DataContext.GetCommand()
LINQ to SQL we can read the generated T_SQL query using DataContext.Log or SQLQueryVisualizer. But If you are working with WebProject the Log property not very much convenient as you have to use TextWriter to dump the generated T-SQL query.
In Orcas Beta 1 we had DataContext.GetQueryText which used to give us the generated T-SQL now we do not have this from Visual Studio 2008 Beta 2. I have mentioned about this change in one of my earlier Blog post. The implementation is here,
TextBox1.Text = db.GetCommand(query).CommandText;
Now this will give you the DataContext generated T-SQL query.
Namoskar!!!
Comments
Anonymous
November 09, 2007
LINQ to SQL we can read the generated T_SQL query using DataContext.Log or SQLQueryVisualizer. But IfAnonymous
November 19, 2007
Welcome to the thirty-sixth issue of Community Convergence. This is the big day, with Visual Studio 2008Anonymous
November 19, 2007
Welcome to the thirty-sixth issue of Community Convergence. This is the big day, with Visual Studio 2008Anonymous
September 07, 2009
Hi guys, Why Linq to SQL connects to DataBase while executing db.GetCommand(query).CommandText; ? Because I believe it has everything on code side and there is no need to connect to database to convert LINQ grammer to SQL Syntax. So why it requires the accurate Connection string on DataContext to connect to DB ? I'm looking for the possiblity of getting the SQL Command Text without connecting to DataBase. Anybody can help ?Anonymous
February 04, 2010
Same Problem as Mohsen. I want to take advantage of the already existing linq to sql parser for writing an own generator that converts linq to sql code. It should be possible even if the database does not exist until now. Is that possible?