-
-
Notifications
You must be signed in to change notification settings - Fork 84
Description
Description
When adding a filter to a byte-backed enum field which is stored as a (in Sql Server) 'tinyint' column an unnecessary CAST ( x AS int ) is generated, causing unnecessary strain on the database.
E.g. a field of the following type:
public enum CustomerStatus : byte {
Normal = 0,
Inactive = 1,
Deleted = 2
}
With the following filter:
modelBuilder.Filter("IsNotDeleted", (Customer d, CustomerStatus status) => d.Status != status, CustomerStatus.Deleted);
Will generate the following SQL:
SELECT
[Extent1].[CustomerID] AS [CustomerID],
[Extent1].[Name] AS [Name],
[Extent1].[Status] AS [Status]
FROM [dbo].[Customers] AS [Extent1]
WHERE ( CAST( [Extent1].[Status] AS int) <> CAST( @DynamicFilterParam_000001 AS int))
The expected result should be:
SELECT
[Extent1].[CustomerID] AS [CustomerID],
[Extent1].[Name] AS [Name],
[Extent1].[Status] AS [Status]
FROM [dbo].[Customers] AS [Extent1]
WHERE ( [Extent1].[Status] <> @DynamicFilterParam_000001 )
Fiddle or Project
https://dotnetfiddle.net/3iJBCx
Further technical details
- EF version: 6.3
- EF DynamicFilters version: 3.1.0
- Database Provider: SqlServer