У меня есть 2 класса (EF Models), представленные как набор сущностей оддаты,
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
[Required]
public Address Address { get; set; }
}
public class Address
{
public int Id { get; set; }
public string State { get; set; }
public string City { get; set; }
}
Когда я запрашиваю клиентов в определенном городе с использованием фильтра оддаты, например
http://localhost:62680/odata/Customers?$expand=Address&$filter=Address/City eq 'Chennai'
Создает следующий неэффективный sql с фильтрацией города, выполненной в WHERE Clause,
SELECT
[Extent1].[Id] AS [Id],
N'462b9c81-0a7a-4015-aa08-bcdb2ec067ec' AS [C1],
[Extent1].[Name] AS [Name],
[Extent1].[Address_Id] AS [Address_Id],
cast(1 as bit) AS [C2],
N'Address' AS [C3],
N'462b9c81-0a7a-4015-aa08-bcdb2ec067ec' AS [C4],
[Extent2].[Id] AS [Id1],
[Extent2].[State] AS [State],
[Extent2].[City] AS [City],
cast(1 as bit) AS [C5],
cast(0 as bit) AS [C6]
FROM [dbo].[Customers] AS [Extent1]
INNER JOIN [dbo].[Addresses] AS [Extent2] ON [Extent1].[Address_Id] = [Extent2].[Id]
WHERE ([Extent2].[City] = @p__linq__0)
В идеале, он должен был сгенерироватьзапрос с и предложением Inner join для фильтрации города, как показано ниже
SELECT
[Extent1].[Id] AS [Id],
N'462b9c81-0a7a-4015-aa08-bcdb2ec067ec' AS [C1],
[Extent1].[Name] AS [Name],
[Extent1].[Address_Id] AS [Address_Id],
cast(1 as bit) AS [C2],
N'Address' AS [C3],
N'462b9c81-0a7a-4015-aa08-bcdb2ec067ec' AS [C4],
[Extent2].[Id] AS [Id1],
[Extent2].[State] AS [State],
[Extent2].[City] AS [City],
cast(1 as bit) AS [C5],
cast(0 as bit) AS [C6]
FROM [dbo].[Customers] AS [Extent1]
INNER JOIN [dbo].[Addresses] AS [Extent2] ON [Extent1].[Address_Id] = [Extent2].[Id]
and ([Extent2].[City] = @p__linq__0)
Есть ли способ повлиять на процесс генерации запроса для запроса Odata.Пожалуйста, порекомендуйте.
Информация библиотеки:
Microsoft.AspNet.OData: 7.0.1 Entity Framework: 6.2