LINQ-LINQ to SQL与LINQPad的结果不同 [英] LINQ - Different results with LINQ to SQL vs LINQPad

查看:66
本文介绍了LINQ-LINQ to SQL与LINQPad的结果不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LINQ to SQL和LINQPad执行相同"查询,但是结果集的输出略有不同.

I am executing the "same" query using LINQ to SQL and in LINQPad, however the result set comes out slightly differently.

代码是

var conn = new SqliteConnection (
            "DbLinqProvider=Sqlite;" + 
            "Data Source=/home/larsenma/database.golden"
        );

Models.Main db = new Models.Main (conn);

var runSum =
  from rr in db.Runrecords
  group rr by rr.RunID into rg          
  select new 
  {
    LaneCount = rg.Count(),
  }

LINQPad正确计算了"LaneCount",而使用LINQ to SQL,我为每条记录得到1s.​​

LINQPad properly calculates the "LaneCount" while with LINQ to SQL I get 1s for each record.

在LINQ to SQL中,我使用sqlmetal生成了DBLinq的映射,在LINQPad中使用了IQ驱动程序.我的数据库是SQLite.

With LINQ to SQL I used sqlmetal to generate my mapping for DBLinq and with LINQPad is used the IQ driver. My database is SQLite.

我对LINQ东西还很陌生,有什么想法我做错了吗?

I'm rather new to this LINQ stuff, any ideas where I am going wrong?

编辑

我已将查询简化为极简的可复制实例.当我调试生成的SQL时,我得到

I've simplified my query to the minimalist reproducible instance. When I debug the generated SQL I get

SELECT (SELECT COUNT(*))
FROM runrecords
GROUP BY RunID

这是第二个"COUNT(*)"遗漏的东西.

It is the second "COUNT(*)" that is missing things up.

谢谢.

推荐答案

听起来您正在使用DBLinq,而不是LINQ to SQL. sqlmetal工具生成实体类和类型化的DataContext-但是,如果您使用的是DBLinq,则实际上是将LINQ转换为SQL的是DBLinq.

It sounds like you're using DBLinq, not LINQ to SQL. The sqlmetal tool generates entity classes and a typed DataContext - however if you're using DBLinq, then it's DBLinq that's actually translating LINQ into SQL.

当我上一次查看DBLinq时(一两年前),它是相当原始的,甚至涉及一些基本查询. LINQPad的IQ驱动程序使用马特·沃伦(Matt Warren)的IQueryable工具包,它可能是可用于将LINQ转换为SQL的最复杂的与提供程序无关的引擎. DevArt的另一个不错的引擎是DevArt的LINQ Connect库-这在最近已经走了很长一段路,并且还支持SQLite.

When I last looked at DBLinq (a year or two ago) it was fairly primitive and fell over on even some basic queries. LINQPad's IQ driver uses Matt Warren's IQueryable toolkit which is probably the most sophisticated provider-agnostic engine available for translating LINQ into SQL. Another good engine is DevArt's LINQ Connect library - this has come a long way in recent times and also supports SQLite.

现在,我正在更新IQ驱动程序以支持Oracle,并且还计划对IQueryable库本身发布一些增强功能.您为什么不尝试使用此库或DevArt的库.

Right now I'm in the process of updating the IQ driver to support Oracle, and also plan on posting some enhancements to the IQueryable library itself. Why don't you try using either this or DevArt's library.

这篇关于LINQ-LINQ to SQL与LINQPad的结果不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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