如何检测EF视图生成 [英] How to detect EF view generation

查看:61
本文介绍了如何检测EF视图生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以检测EF何时生成视图而不是使用在程序集中编译生成的视图类。


是否有任何标记/设置跟踪视图生成的某个地方还是有任何我可以订阅的事件? (仅用于调试目的)


最好的问候Max




解决方案

你好iL MaX;
$


不确定你的意思,"EF生成视图而不是使用生成的在程序集中编译的视图类。",您是否想要查看SQL服务器的SQL语句是什么?如果是这样,那么下面将会这样做。

 //示例代码用于Northwind示例db 
//变量查询将SQL发送到DB
//查询结果
使用(var ctx = new NorthwindEntities())
{
var results = from c in ctx.Customers
其中c .City ==" London"
选择c;

var query =((ObjectQuery)(results))。ToTraceString();

Console.Writeline(查询);

}

  



Hi, i would to know if is possible to detect when EF generate views instead of using the generated views class compiled in the assembly.

Is there any flag/setting somewhere to trace the view generation or is there any event that i could subscribe? (only for debug purpose)

Best regards Max


解决方案

Hi iL MaX;

Not sure what you mean by, "EF generate views instead of using the generated views class compiled in the assembly.", Do you mean that you want to see what SQL statements are being set to the SQL server? if so then the following will do that.

// Sample code is for the Northwind sample db 
// The variable query will have the SQL sent to the DB 
// for the query results
using( var ctx = new NorthwindEntities())
{
	var results = from c in ctx.Customers
    	          where c.City == "London"
        	      select c;
              
	var query = ((ObjectQuery)(results)).ToTraceString();
	
	Console.Writeline(query);
	
}

  


这篇关于如何检测EF视图生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆