SubSonic3:方法"FirstOrDefault". SQL Server 2000引发异常 [英] SubSonic3: Method "FirstOrDefault" throws exception with SQL Server 2000

查看:66
本文介绍了SubSonic3:方法"FirstOrDefault". SQL Server 2000引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server 2000中使用SubSonic3.

我对方法"FirstOrDefault"有问题-它总是在SubSonic.Linq dll中抛出异常=第1行:'('."附近的语法不正确

编辑(从注释中添加了代码):

InventoryDAL = DAL project name (dll) 
Inventort= Subsonic3 Gnerated classes 
Name space WHWarehouses = gnerated object 

Dim WareH = (From Wh In InventoryDAL.Inventort.WHWarehouses.All _ 
  Where Wh.WarehouseID = 1 ).FirstOrDefault

解决方案

这也是我遇到的一个问题,不幸的是,用于生成TOP的代码是在SubSonic依赖关系中生成的,无法在TT模板中进行更改. /p>

在Substrong中,在 TSqlFormatter .cs类下的方法是

protected override Expression VisitSelect(SelectExpression select)

...

if (select.Take != null)
            {
                sb.Append("TOP (");
                this.Visit(select.Take);
                sb.Append(") ");
            }

....

去掉db.Append中的括号应该可以解决SQL的问题,但是我不确定这是否会破坏SQL Compact Edition等其他提供程序?

我在这里提出了这个问题:带有TOP关键字的SubSonic Bug?查询.

希望这会有所帮助.

I am using SubSonic3 with SQL Server 2000.

I have problem with the method "FirstOrDefault" - it always throws an exception = "Line 1: Incorrect syntax near '('." from the SubSonic.Linq dll

EDIT (Added code from comment):

InventoryDAL = DAL project name (dll) 
Inventort= Subsonic3 Gnerated classes 
Name space WHWarehouses = gnerated object 

Dim WareH = (From Wh In InventoryDAL.Inventort.WHWarehouses.All _ 
  Where Wh.WarehouseID = 1 ).FirstOrDefault

解决方案

This is a problem I've encountered too and unfortunately the code to generate the TOP is generated in the SubSonic Dependency and cannot be changed in the TT templates.

In the SubSonic source under TSqlFormatter.cs class is a method

protected override Expression VisitSelect(SelectExpression select)

...

if (select.Take != null)
            {
                sb.Append("TOP (");
                this.Visit(select.Take);
                sb.Append(") ");
            }

....

Removing the brackets in db.Append should fix the issue for SQL but I'm not sure whether this may break other providers such as SQL Compact Edition?

I raised it here: SubSonic Bug with TOP keyword? before I read you query.

Hope this helps.

这篇关于SubSonic3:方法"FirstOrDefault". SQL Server 2000引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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