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
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
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