查了许久都没有找到方法.
myContext context = new myContext();
string esql = "SELECT VALUE it FROM myContext.DBItemList as it";
ObjectQuery<DBItemList> query = context.CreateQuery<DBItemList>(esql);
Console.WriteLine(query.CommandText);//获取esql
Console.WriteLine(query.ToTraceString());//获取sql
输出结果:
SELECT VALUE it FROM myContext.DBItemList as it
SELECT
[Extent1].[AutoId] AS [AutoId],
[Extent1].[NameID] AS [NameID],
[Extent1].[ItemID] AS [ItemID],
[Extent1].[ItemValue] AS [ItemValue]
FROM [dbo].[DBItemList] AS [Extent1]
原文:http://www.cnblogs.com/foundation/archive/2008/10/06/1304703.html#_Toc211066307
ToTraceString());就是这个方法