显示带有EF4.1的ToString()的SQL命令
我有一个EF4.1数据库优先应用程序,.ToString()方法仅给我反映类型,
I have an EF4.1 database first application, and the .ToString() method is only giving me the reflected type, and not the SQL query.
如何使我的应用程序以SQL格式向我显示Linq查询?
How do I make my application show me the Linq query in SQL format?
我已将C:\Program Files (x86)\Microsoft ADO.NET Entity Framework 4.1\Binaries\EntityFramework.dll
的4.1版本添加到我的项目中.我猜想ToString功能是通过扩展方法添加的,但是即使添加使用system.data.Entity",我也无法使字符串输出正常工作.
I've added version 4.1 of C:\Program Files (x86)\Microsoft ADO.NET Entity Framework 4.1\Binaries\EntityFramework.dll
to my project. I'm guessing the ToString feature is added by an extension method, but even when I add "Using system.data.Entity" I'm unable to getthe string output to work.
这是否意味着ToString仅适用于Code First部署?
Does this mean ToString only works for Code First deployments?
public IEnumerable<CompanyDetail> GetAllCompanies(int? startPage, int? stopPage, string Filter, int? MaxResults)
{
var t = from c in _entities.CompanyDetail
select c;
string test = t.ToString();
var t2 = _entities.CompanyDetail;
string test2 = t2.ToString();
return t.ToList();
}
我可以确认它适用于数据库优先应用程序.
I can confirm that it works for database first applications.
我猜您的代码仍在使用EF 4类,因为您没有提到在模型中添加EF 4.1 DbContext生成器.在这种情况下,您可以右键单击该模型,选择添加代码生成项...",然后选择ADO.NET C#DbContext Generator.如果您没有在已安装的模板中看到它,请在在线模板"下查找它.
I am guessing your code is still using the EF 4 classes since you didn't mention adding the EF 4.1 DbContext generator to your model. If that's the case, you can right-click on the model, choose "Add Code Generation Item..." and select the ADO.NET C# DbContext Generator. If you don't see it in your installed templates, look for it under Online Templates.