我将我的sql数据库转换为sql compact,现在我在组中获取了linq查询错误以及where子句
这是我的查询
from s in ServiceSheets
join b in Branches on s.BranchId equals b.Id
join r in Resellers on s.CustomerId equals r.Id
join add in Addresses on r.AddressId equals add.Id into address
from a in address.DefaultIfEmpty()
where (string.IsNullOrEmpty(filters.Name) || s.Name.ToLower().Contains(filters.Name.ToLower()))
&& (string.IsNullOrEmpty(filters.Customer) || r.FirstName.ToLower().Contains(filters.Customer.ToLower()) || r.LastName.ToLower().Contains(filters.Customer.ToLower()))
&& (filters.Status == "SelectAll" || (filters.Status == "Completed" && s.InvoiceNo > 0) || (filters.Status == "Pending" && s.InvoiceNo == null))
&& (string.IsNullOrEmpty(filters.BranchName) || b.Name.ToLower().Contains(filters.BranchName.ToLower()))
&& (s.ExpectedDate >= filters.FromDate && s.ExpectedDate <= filters.ToDate)
&& s.ApplicationId == CurrentApplicationId
&& (s.IsDeleted == null || s.IsDeleted == false)
select s
这是sql查询
{SELECT
1 AS [C1],
[Filter1].[Id1] AS [Id],
[Filter1].[Name1] AS [Name],
[Filter1].[Name2] AS [Name1],
[Filter1].[Id2] AS [Id1],
CASE WHEN ([Filter1].[ExpectedDate] IS NULL) THEN @p__linq__13 ELSE [Filter1].[ExpectedDate] END AS [C2],
CASE WHEN ([Filter1].[ExpectedPrice] IS NULL) THEN cast(0 as float) ELSE [Filter1].[ExpectedPrice] END AS [C3],
CASE WHEN ([Filter1].[SerialNumber] IS NULL) THEN cast(0 as float) ELSE [Filter1].[SerialNumber] END AS [C4],
CASE WHEN ([Filter1].[InvoiceNo] IS NULL) THEN cast(0 as float) ELSE [Filter1].[InvoiceNo] END AS [C5],
[Filter1].[Description1] AS [Description],
CASE WHEN ([Filter1].[IsDeleted1] IS NULL) THEN cast(0 as bit) ELSE [Filter1].[IsDeleted1] END AS [C6],
@p__linq__14 AS [C7],
[Filter1].[Id3] AS [Id2],
[Filter1].[FirstName] AS [FirstName],
[Filter1].[LastName] AS [LastName],
CASE WHEN ([Filter1].[DiscountPercentage] IS NULL) THEN cast(0 as float) ELSE [Filter1].[DiscountPercentage] END AS [C8],
CASE WHEN ([Filter1].[UpdatedBy1] IS NULL) THEN @p__linq__15 ELSE [Filter1].[UpdatedBy1] END AS [C9],
CASE WHEN ([Filter1].[UpdatedDate1] IS NULL) THEN @p__linq__16 ELSE [Filter1].[UpdatedDate1] END AS [C10],
CASE WHEN ([Filter1].[CreatedBy1] IS NULL) THEN @p__linq__17 ELSE [Filter1].[CreatedBy1] END AS [C11],
CASE WHEN ([Filter1].[CreatedDate1] IS NULL) THEN @p__linq__18 ELSE [Filter1].[CreatedDate1] END AS [C12],
CASE WHEN ([Filter1].[IsDeleted2] IS NULL) THEN cast(0 as bit) ELSE [Filter1].[IsDeleted2] END AS [C13],
CASE WHEN ([Filter1].[IsShareable1] IS NULL) THEN cast(0 as bit) ELSE [Filter1].[IsShareable1] END AS [C14],
CASE WHEN ([Filter1].[IsSynced1] IS NULL) THEN cast(0 as bit) ELSE [Filter1].[IsSynced1] END AS [C15],
@p__linq__19 AS [C16],
CASE WHEN ([Filter1].[Type] IS NULL) THEN 1 ELSE [Filter1].[Type] END AS [C17],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__20 ELSE [Extent4].[Id] END AS [C18],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[AddressLine1] END AS [C19],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[AddressLine2] END AS [C20],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[City] END AS [C21],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[State] END AS [C22],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[ZipCode] END AS [C23],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[Country] END AS [C24],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[PhoneNo] END AS [C25],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[MobileNo] END AS [C26],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[Email] END AS [C27],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__21 WHEN ([Extent4].[UpdatedBy] IS NULL) THEN @p__linq__22 ELSE [Extent4].[UpdatedBy] END AS [C28],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__23 WHEN ([Extent4].[UpdatedDate] IS NULL) THEN @p__linq__24 ELSE [Extent4].[UpdatedDate] END AS [C29],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__25 WHEN ([Extent4].[CreatedBy] IS NULL) THEN @p__linq__26 ELSE [Extent4].[CreatedBy] END AS [C30],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__27 WHEN ([Extent4].[CreatedDate] IS NULL) THEN @p__linq__28 ELSE [Extent4].[CreatedDate] END AS [C31],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN cast(0 as bit) WHEN ([Extent4].[IsDeleted] IS NULL) THEN cast(0 as bit) ELSE [Extent4].[IsDeleted] END AS [C32],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN cast(0 as bit) WHEN ([Extent4].[IsShareable] IS NULL) THEN cast(0 as bit) ELSE [Extent4].[IsShareable] END AS [C33],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN cast(0 as bit) WHEN ([Extent4].[IsSynced] IS NULL) THEN cast(0 as bit) ELSE [Extent4].[IsSynced] END AS [C34],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__29 ELSE [Extent4].[ApplicationId] END AS [C35]
FROM (SELECT [Extent1].[Id] AS [Id1], [Extent1].[Name] AS [Name1], [Extent1].[Description] AS [Description1], [Extent1].[CustomerId] AS [CustomerId], [Extent1].[ExpectedDate] AS [ExpectedDate], [Extent1].[ExpectedPrice] AS [ExpectedPrice], [Extent1].[InvoiceNo] AS [InvoiceNo], [Extent1].[SerialNumber] AS [SerialNumber], [Extent1].[ApplicationId] AS [ApplicationId1], [Extent1].[IsDeleted] AS [IsDeleted1], [Extent1].[BranchId] AS [BranchId1], [Extent2].[Id] AS [Id2], [Extent2].[Name] AS [Name2], [Extent2].[Description] AS [Description2], [Extent2].[UpdatedBy] AS [UpdatedBy2], [Extent2].[UpdatedDate] AS [UpdatedDate2], [Extent2].[CreatedBy] AS [CreatedBy2], [Extent2].[CreatedDate] AS [CreatedDate2], [Extent2].[IsDeleted] AS [IsDeleted3], [Extent2].[IsSynced] AS [IsSynced2], [Extent2].[IsShareable] AS [IsShareable2], [Extent2].[ApplicationId] AS [ApplicationId2], [Extent2].[AddressId] AS [AddressId1], [Extent2].[Logo] AS [Logo], [Extent2].[LogoType] AS [LogoType], [Extent3].[Id] AS [Id3], [Extent3].[FirstName] AS [FirstName], [Extent3].[LastName] AS [LastName], [Extent3].[DiscountPercentage] AS [DiscountPercentage], [Extent3].[UpdatedBy] AS [UpdatedBy1], [Extent3].[UpdatedDate] AS [UpdatedDate1], [Extent3].[CreatedBy] AS [CreatedBy1], [Extent3].[CreatedDate] AS [CreatedDate1], [Extent3].[IsDeleted] AS [IsDeleted2], [Extent3].[IsSynced] AS [IsSynced1], [Extent3].[IsShareable] AS [IsShareable1], [Extent3].[ApplicationId] AS [ApplicationId3], [Extent3].[AddressId] AS [AddressId2], [Extent3].[Type] AS [Type], [Extent3].[IdentificationId] AS [IdentificationId], [Extent3].[BranchId] AS [BranchId2]
FROM [ServiceSheet] AS [Extent1]
INNER JOIN [Branch] AS [Extent2] ON [Extent1].[BranchId] = [Extent2].[Id]
INNER JOIN [Reseller] AS [Extent3] ON [Extent1].[CustomerId] = [Extent3].[Id]
WHERE ([Extent1].[IsDeleted] IS NULL) OR (0 = [Extent1].[IsDeleted]) ) AS [Filter1]
LEFT OUTER JOIN [Address] AS [Extent4] ON [Filter1].[AddressId2] = [Extent4].[Id]
WHERE ((cast(@p__linq__0 as ntext) IS NULL) OR ((LEN(@p__linq__0)) = 0) OR ((CHARINDEX(LOWER(@p__linq__1), LOWER([Filter1].[Name1]))) > 0)) AND ((cast(@p__linq__2 as ntext) IS NULL) OR ((LEN(@p__linq__2)) = 0) OR ((CHARINDEX(LOWER(@p__linq__3), LOWER([Filter1].[FirstName]))) > 0) OR ((CHARINDEX(LOWER(@p__linq__4), LOWER([Filter1].[LastName]))) > 0)) AND ((N'SelectAll' = @p__linq__5) OR ((N'Completed' = @p__linq__6) AND ([Filter1].[InvoiceNo] > cast(0 as float))) OR ((N'Pending' = @p__linq__7) AND ([Filter1].[InvoiceNo] IS NULL))) AND ((cast(@p__linq__8 as ntext) IS NULL) OR ((LEN(@p__linq__8)) = 0) OR ((CHARINDEX(LOWER(@p__linq__9), LOWER([Filter1].[Name2]))) > 0)) AND ([Filter1].[ExpectedDate] >= @p__linq__10) AND ([Filter1].[ExpectedDate] <= @p__linq__11) AND ([Filter1].[ApplicationId1] = @p__linq__12)}
错误
p__linq__7:字符串截断:max = 7,len = 9,value =&#39; SelectAll&#39;
我在group子句和where子句中都遇到了上述错误。请有人指点我正确的方向吗?
答案 0 :(得分:0)
可能是您的某个列无法容纳数据,并且正在尝试将9个字符放入只能容纳7的列中。
答案 1 :(得分:0)
我将filters.Status == "SelectAll"
更改为filters.Status.Contains("Select All")
,在这种情况下它对我有用。如果我想要filters.Status == "SelectAll"
或filters.Status.Equals("SelectAll")
,我们仍然不知道它将如何运作。
以下是使用filters.Status.Contains("Select All")
生成的查询。
SELECT
1 AS [C1],
[Filter1].[Id1] AS [Id],
[Filter1].[Name1] AS [Name],
[Filter1].[Name2] AS [Name1],
[Filter1].[Id2] AS [Id1],
CASE WHEN ([Filter1].[ExpectedDate] IS NULL) THEN @p__linq__13 ELSE [Filter1].[ExpectedDate] END AS [C2],
CASE WHEN ([Filter1].[ExpectedPrice] IS NULL) THEN cast(0 as float) ELSE [Filter1].[ExpectedPrice] END AS [C3],
CASE WHEN ([Filter1].[SerialNumber] IS NULL) THEN cast(0 as float) ELSE [Filter1].[SerialNumber] END AS [C4],
CASE WHEN ([Filter1].[InvoiceNo] IS NULL) THEN cast(0 as float) ELSE [Filter1].[InvoiceNo] END AS [C5],
[Filter1].[Description1] AS [Description],
CASE WHEN ([Filter1].[IsDeleted1] IS NULL) THEN cast(0 as bit) ELSE [Filter1].[IsDeleted1] END AS [C6],
@p__linq__14 AS [C7],
[Filter1].[Id3] AS [Id2],
[Filter1].[FirstName] AS [FirstName],
[Filter1].[LastName] AS [LastName],
CASE WHEN ([Filter1].[DiscountPercentage] IS NULL) THEN cast(0 as float) ELSE [Filter1].[DiscountPercentage] END AS [C8],
CASE WHEN ([Filter1].[UpdatedBy1] IS NULL) THEN @p__linq__15 ELSE [Filter1].[UpdatedBy1] END AS [C9],
CASE WHEN ([Filter1].[UpdatedDate1] IS NULL) THEN @p__linq__16 ELSE [Filter1].[UpdatedDate1] END AS [C10],
CASE WHEN ([Filter1].[CreatedBy1] IS NULL) THEN @p__linq__17 ELSE [Filter1].[CreatedBy1] END AS [C11],
CASE WHEN ([Filter1].[CreatedDate1] IS NULL) THEN @p__linq__18 ELSE [Filter1].[CreatedDate1] END AS [C12],
CASE WHEN ([Filter1].[IsDeleted2] IS NULL) THEN cast(0 as bit) ELSE [Filter1].[IsDeleted2] END AS [C13],
CASE WHEN ([Filter1].[IsShareable1] IS NULL) THEN cast(0 as bit) ELSE [Filter1].[IsShareable1] END AS [C14],
CASE WHEN ([Filter1].[IsSynced1] IS NULL) THEN cast(0 as bit) ELSE [Filter1].[IsSynced1] END AS [C15],
@p__linq__19 AS [C16],
CASE WHEN ([Filter1].[Type] IS NULL) THEN 1 ELSE [Filter1].[Type] END AS [C17],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__20 ELSE [Extent4].[Id] END AS [C18],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[AddressLine1] END AS [C19],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[AddressLine2] END AS [C20],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[City] END AS [C21],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[State] END AS [C22],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[ZipCode] END AS [C23],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[Country] END AS [C24],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[PhoneNo] END AS [C25],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[MobileNo] END AS [C26],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN N'' ELSE [Extent4].[Email] END AS [C27],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__21 WHEN ([Extent4].[UpdatedBy] IS NULL) THEN @p__linq__22 ELSE [Extent4].[UpdatedBy] END AS [C28],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__23 WHEN ([Extent4].[UpdatedDate] IS NULL) THEN @p__linq__24 ELSE [Extent4].[UpdatedDate] END AS [C29],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__25 WHEN ([Extent4].[CreatedBy] IS NULL) THEN @p__linq__26 ELSE [Extent4].[CreatedBy] END AS [C30],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__27 WHEN ([Extent4].[CreatedDate] IS NULL) THEN @p__linq__28 ELSE [Extent4].[CreatedDate] END AS [C31],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN cast(0 as bit) WHEN ([Extent4].[IsDeleted] IS NULL) THEN cast(0 as bit) ELSE [Extent4].[IsDeleted] END AS [C32],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN cast(0 as bit) WHEN ([Extent4].[IsShareable] IS NULL) THEN cast(0 as bit) ELSE [Extent4].[IsShareable] END AS [C33],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN cast(0 as bit) WHEN ([Extent4].[IsSynced] IS NULL) THEN cast(0 as bit) ELSE [Extent4].[IsSynced] END AS [C34],
CASE WHEN (([Extent4].[Id] IS NULL) AND ([Extent4].[ApplicationId] IS NULL)) THEN @p__linq__29 ELSE [Extent4].[ApplicationId] END AS [C35]
FROM (SELECT [Extent1].[Id] AS [Id1], [Extent1].[Name] AS [Name1], [Extent1].[Description] AS [Description1], [Extent1].[CustomerId] AS [CustomerId], [Extent1].[ExpectedDate] AS [ExpectedDate], [Extent1].[ExpectedPrice] AS [ExpectedPrice], [Extent1].[InvoiceNo] AS [InvoiceNo], [Extent1].[SerialNumber] AS [SerialNumber], [Extent1].[ApplicationId] AS [ApplicationId1], [Extent1].[IsDeleted] AS [IsDeleted1], [Extent1].[BranchId] AS [BranchId1], [Extent2].[Id] AS [Id2], [Extent2].[Name] AS [Name2], [Extent2].[Description] AS [Description2], [Extent2].[UpdatedBy] AS [UpdatedBy2], [Extent2].[UpdatedDate] AS [UpdatedDate2], [Extent2].[CreatedBy] AS [CreatedBy2], [Extent2].[CreatedDate] AS [CreatedDate2], [Extent2].[IsDeleted] AS [IsDeleted3], [Extent2].[IsSynced] AS [IsSynced2], [Extent2].[IsShareable] AS [IsShareable2], [Extent2].[ApplicationId] AS [ApplicationId2], [Extent2].[AddressId] AS [AddressId1], [Extent2].[Logo] AS [Logo], [Extent2].[LogoType] AS [LogoType], [Extent3].[Id] AS [Id3], [Extent3].[FirstName] AS [FirstName], [Extent3].[LastName] AS [LastName], [Extent3].[DiscountPercentage] AS [DiscountPercentage], [Extent3].[UpdatedBy] AS [UpdatedBy1], [Extent3].[UpdatedDate] AS [UpdatedDate1], [Extent3].[CreatedBy] AS [CreatedBy1], [Extent3].[CreatedDate] AS [CreatedDate1], [Extent3].[IsDeleted] AS [IsDeleted2], [Extent3].[IsSynced] AS [IsSynced1], [Extent3].[IsShareable] AS [IsShareable1], [Extent3].[ApplicationId] AS [ApplicationId3], [Extent3].[AddressId] AS [AddressId2], [Extent3].[Type] AS [Type], [Extent3].[IdentificationId] AS [IdentificationId], [Extent3].[BranchId] AS [BranchId2]
FROM [ServiceSheet] AS [Extent1]
INNER JOIN [Branch] AS [Extent2] ON [Extent1].[BranchId] = [Extent2].[Id]
INNER JOIN [Reseller] AS [Extent3] ON [Extent1].[CustomerId] = [Extent3].[Id]
WHERE ([Extent1].[IsDeleted] IS NULL) OR (0 = [Extent1].[IsDeleted]) ) AS [Filter1]
LEFT OUTER JOIN [Address] AS [Extent4] ON [Filter1].[AddressId2] = [Extent4].[Id]
WHERE ((cast(@p__linq__0 as ntext) IS NULL) OR ((LEN(@p__linq__0)) = 0) OR ((CHARINDEX(LOWER(@p__linq__1), LOWER([Filter1].[Name1]))) > 0)) AND ((cast(@p__linq__2 as ntext) IS NULL) OR ((LEN(@p__linq__2)) = 0) OR ((CHARINDEX(LOWER(@p__linq__3), LOWER([Filter1].[FirstName]))) > 0) OR ((CHARINDEX(LOWER(@p__linq__4), LOWER([Filter1].[LastName]))) > 0)) AND ((@p__linq__5 LIKE N'%Select All%') OR ((@p__linq__6 LIKE N'%Completed%') AND ([Filter1].[InvoiceNo] > cast(0 as float))) OR ((@p__linq__7 LIKE N'%Pending%') AND ([Filter1].[InvoiceNo] IS NULL))) AND ((cast(@p__linq__8 as ntext) IS NULL) OR ((LEN(@p__linq__8)) = 0) OR ((CHARINDEX(LOWER(@p__linq__9), LOWER([Filter1].[Name2]))) > 0)) AND ([Filter1].[ExpectedDate] >= @p__linq__10) AND ([Filter1].[ExpectedDate] <= @p__linq__11) AND ([Filter1].[ApplicationId1] = @p__linq__12)
我们最好使用filters.Status.StartsWith("Select All")
来提高效果。