Это звучит безумно, но факт в том, что я наблюдаю следующее: у меня есть приложение apsx mvc, подключенное к SQL-серверу с использованием EF6. Время от времени я получаю исключение на основе сгенерированного SQL. Например:
Неверный синтаксис рядом с ключевыми словами «AS» и «Неверный синтаксис рядом с [[Extend1]»
(и варианты этого)
По моему лучшему мнению, этого не должно происходить в таких средах, как EF.
К счастью, я ввел перехватчик SQL (например, https://docs.microsoft.com/en-us/ef/ef6/fundamentals/logging-and-interception), который дал мне шанс увидеть SQL перед выполнением. Мой первыйШаг состоял в том, чтобы изучить сгенерированный SQL - и это выглядит вменяемым. На другом шаге я подключил профилировщик к серверу SQL! но это то, что является наблюдателем) Заключение так далеко: время от времени отдельные символы в SQL изменяются (В наблюдаемых случаях это - запятая, которая становится форм-подачей.)
Кто-нибудь в Интернете знает, чтоможет быть фоном для этого?
ОБНОВЛЕНИЕ 1: (Запрашиваемая информация)
=== Код EF ===
public Customer GetById(string id)
{
return DbContext.Customers.Include("Address").FirstOrDefault(a => a.Id == id);
}
=== От Перехватчика ===
2019-11-06 09:07:14.471 +01:00 [Interceptors.SqlLogInterceptor] [44] [<<username>>] [Debug] SELECT
[Limit1].[AddressTypeId] AS [AddressTypeId],
[Limit1].[Id] AS [Id],
[Limit1].[AddressId] AS [AddressId],
[Limit1].[ShowPrebooking] AS [ShowPrebooking],
[Limit1].[Id1] AS [Id1],
[Limit1].[Name1] AS [Name1],
[Limit1].[Name2] AS [Name2],
[Limit1].[Address1] AS [Address1],
[Limit1].[Address2] AS [Address2],
[Limit1].[HouseNumber] AS [HouseNumber],
[Limit1].[PostCode] AS [PostCode],
[Limit1].[City] AS [City],
[Limit1].[State] AS [State],
[Limit1].[CountryCode] AS [CountryCode],
[Limit1].[ContactName] AS [ContactName],
[Limit1].[Email] AS [Email],
[Limit1].[Phone] AS [Phone],
[Limit1].[Mobile] AS [Mobile],
[Limit1].[CreatedByUserId] AS [CreatedByUserId],
[Limit1].[CreatedDateTime] AS [CreatedDateTime],
[Limit1].[UpdatedByUserId] AS [UpdatedByUserId],
[Limit1].[UpdatedDateTime] AS [UpdatedDateTime],
[Limit1].[DeliveryDescription] AS [DeliveryDescription],
[Limit1].[OpeningHoursTo] AS [OpeningHoursTo],
[Limit1].[OpeningHoursFrom] AS [OpeningHoursFrom]
FROM ( SELECT TOP (1)
[Extent1].[Id] AS [Id],
[Extent1].[AddressId] AS [AddressId],
[Extent1].[ShowPrebooking] AS [ShowPrebooking],
[Extent2].[Id] AS [Id1],
[Extent2].[Name1] AS [Name1],
[Extent2].[Name2] AS [Name2],
[Extent2].[Address1] AS [Address1],
[Extent2].[Address2] AS [Address2],
[Extent2].[HouseNumber] AS [HouseNumber],
[Extent2].[PostCode] AS [PostCode],
[Extent2].[City] AS [City],
[Extent2].[State] AS [State],
[Extent2].[CountryCode] AS [CountryCode],
[Extent2].[ContactName] AS [ContactName],
[Extent2].[Email] AS [Email],
[Extent2].[Phone] AS [Phone],
[Extent2].[Mobile] AS [Mobile],
[Extent2].[AddressTypeId] AS [AddressTypeId],
[Extent2].[CreatedByUserId] AS [CreatedByUserId],
[Extent2].[CreatedDateTime] AS [CreatedDateTime],
[Extent2].[UpdatedByUserId] AS [UpdatedByUserId],
[Extent2].[UpdatedDateTime] AS [UpdatedDateTime],
[Extent2].[DeliveryDescription] AS [DeliveryDescription],
[Extent2].[OpeningHoursTo] AS [OpeningHoursTo],
[Extent2].[OpeningHoursFrom] AS [OpeningHoursFrom]
FROM [dbo].[Customers] AS [Extent1]
INNER JOIN [dbo].[Addresses] AS [Extent2] ON [Extent1].[AddressId] = [Extent2].[Id]
WHERE [Extent1].[Id] = @p__linq__0
) AS [Limit1]
2019-11-06 09:07:14.471 +01:00 [Yourleman.Ef.Interceptors.SqlLogInterceptor] [44] [<<username>>] [Debug] -- Failed in 1 ms with error: Incorrect syntax near 'Limit1'.
Incorrect syntax near the keyword 'AS'.
=== Трассировка от профилировщика ===
exec sp_executesql N'SELECT
[Limit1].[AddressTypeId] AS [AddressTypeId],
[Limit1].[Id] AS [Id],
[Limit1].[AddressId] AS [AddressId],
[Limit1].[ShowPrebooking] AS [ShowPrebooking],
[Limit1].[Id1] AS [Id1],
[Limit1].[Name1] AS [Name1],
[Limit1].[Name2] AS [Name2],
[Limit1].[Address1] AS [Address1],
[Limit1].[Address2] AS [Address2],
[Limit1].[HouseNumber] AS [HouseNumber],
[Limit1].[PostCode] AS [PostCode],
[Limit1].[City] AS [City],
[Limit1].[State] AS [State],
[Limit1].[CountryCode] AS [CountryCode],
[Limit1].[ContactName] AS [ContactName],
[Limit1].[Email] AS [Email],
[Limit1].[Phone] AS [Phone],
[Limit1].[Mobile] AS [Mobile],
[Limit1].[CreatedByUserId] AS [CreatedByUserId],
[Limit1].[CreatedDateTime] AS [CreatedDateTime],
[Limit1].[UpdatedByUserId] AS [UpdatedByUserId],
[Limit1].[UpdatedDateTime] AS [UpdatedDateTime],
[Limit1].[DeliveryDescription] AS [DeliveryDescription],
[Limit1].[OpeningHoursTo] AS [OpeningHoursTo]
[Limit1].[OpeningHoursFrom] AS [OpeningHoursFrom]
FROM ( SELECT TOP (1)
[Extent1].[Id] AS [Id],
[Extent1].[AddressId] AS [AddressId],
[Extent1].[ShowPrebooking] AS [ShowPrebooking],
[Extent2].[Id] AS [Id1],
[Extent2].[Name1] AS [Name1],
[Extent2].[Name2] AS [Name2],
[Extent2].[Address1] AS [Address1],
[Extent2].[Address2] AS [Address2],
[Extent2].[HouseNumber] AS [HouseNumber],
[Extent2].[PostCode] AS [PostCode],
[Extent2].[City] AS [City],
[Extent2].[State] AS [State],
[Extent2].[CountryCode] AS [CountryCode],
[Extent2].[ContactName] AS [ContactName],
[Extent2].[Email] AS [Email],
[Extent2].[Phone] AS [Phone],
[Extent2].[Mobile] AS [Mobile],
[Extent2].[AddressTypeId] AS [AddressTypeId],
[Extent2].[CreatedByUserId] AS [CreatedByUserId],
[Extent2].[CreatedDateTime] AS [CreatedDateTime],
[Extent2].[UpdatedByUserId] AS [UpdatedByUserId],
[Extent2].[UpdatedDateTime] AS [UpdatedDateTime],
[Extent2].[DeliveryDescription] AS [DeliveryDescription],
[Extent2].[OpeningHoursTo] AS [OpeningHoursTo],
[Extent2].[OpeningHoursFrom] AS [OpeningHoursFrom]
FROM [dbo].[Customers] AS [Extent1]
INNER JOIN [dbo].[Addresses] AS [Extent2] ON [Extent1].[AddressId] = [Extent2].[Id]
WHERE [Extent1].[Id] = @p__linq__0
) AS [Limit1]',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'2341234'
Изучите байты, показавшие, что после [OpeningHoursTo] есть символ Фида формы (\ u000C)