【问题标题】:Why is the SQL query from Entity Framework not visible in the Sql Server Profiler when query contains declared variables?为什么当查询包含声明的变量时,来自 Entity Framework 的 SQL 查询在 Sql Server Profiler 中不可见?
【发布时间】:2013-01-16 09:43:34
【问题描述】:

一段代码:

        using (var dc = new Database())
        {
            var results = from a in dc.Article
                          where a.IdNeswpaper == 12
                          select new
                          {
                              a.Id,                               
                          };
            dataGrid1.ItemsSource = results;
        }

此查询在 Sql Profiler 中可见,但是:

        int idNews = 12;
        using (var dc = new Database())
        {
            var results = from a in dc.Article
                          where a.IdNeswpaper == idNews
                          select new
                          {
                              a.Id,                               
                          };
            dataGrid1.ItemsSource = results;
        }

不可见,两者都正确完成并显示数据。 为什么第二个查询在 Sql Profiler 中不可见? 有什么想法吗?

【问题讨论】:

    标签: c# entity-framework sql-server-profiler


    【解决方案1】:

    我不想告诉你,但你必须看起来更好。查询就在那里。也许你把它过滤掉了?

    要点是 - 如果不提​​交 SQL 文本,就无法通过连接从数据库中提取数据。没有任何。因此,要获取数据,查询必须存在。

    【讨论】:

    • 我知道,但查询仅在第二个示例中不可见,这很奇怪
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 2016-12-02
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多