-4

我正在尝试编写自定义查询并不断返回

SqlException 未处理“错误”-“。”附近的语法不正确

代码:

var list = dbcontext.Database.SqlQuery<string>("SELECT a.AssetID, a.AssetName, a.Seg1_Code, d.ShortName, e.OfficePercentage, e.MaintenancePercentage" +
           "FROM [Core].[dbo].[Asset] a" +
           "LEFT OUTER JOIN [Core].[dbo].[AssetAddress] b" +
           "ON a.AssetID = b.AssetID" +
           "LEFT OUTER JOIN [Core].[dbo].[Address] c" +
           "ON b.AddressID = c.AddressID" +
           "LEFT OUTER JOIN [Core].[dbo].[StateLookup] d" +
           "ON c.StateID = d.StateID" +
           "INNER JOIN [Core].[dbo].[AssetPayrollMarkupOverride] e" +
           "ON a.AssetID = e.AssetID" +
           "ORDER BY d.ShortName, a.AssetName").ToList();
4

1 回答 1

4

在串联的每个字符串之前/之后添加空格。

 var list = dbcontext.Database.SqlQuery<string>(
                    "SELECT a.AssetID, a.AssetName, a.Seg1_Code, d.ShortName, e.OfficePercentage, e.MaintenancePercentage" +
                    " FROM [Core].[dbo].[Asset] a" +
                    " LEFT OUTER JOIN [Core].[dbo].[AssetAddress] b" +
                    " ON a.AssetID = b.AssetID" +
                    " LEFT OUTER JOIN [Core].[dbo].[Address] c" +
                    " ON b.AddressID = c.AddressID" +
                    " LEFT OUTER JOIN [Core].[dbo].[StateLookup] d" +
                    " ON c.StateID = d.StateID" +
                    " INNER JOIN [Core].[dbo].[AssetPayrollMarkupOverride] e" +
                    " ON a.AssetID = e.AssetID" +
                    " ORDER BY d.ShortName, a.AssetName").ToList();

(在上面的代码中,我在新字符串开始之前添加了空格)

于 2013-07-31T14:06:59.383 回答