SubSonic3: Method “FirstOrDefault” throws exception with SQL Server 2000

▼魔方 西西 提交于 2019-12-02 20:08:26

问题


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

回答1:


I don't know SubSonic, but Hibernate has different dialects of SQL you can tell it to use, might want to see if there is any way to tell it to use a dialect for SQL 2000




回答2:


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.



来源:https://stackoverflow.com/questions/1397933/subsonic3-method-firstordefault-throws-exception-with-sql-server-2000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!