The Gridify.EntityFramework package includes two additional methods: GridifyAsync() and GridifyQueryableAsync().
Install-Package Gridify.EntityFramework -Version {{ $version }}
dotnet add package Gridify.EntityFramework --version {{ $version }}
To use Gridify with Entity Framework, enable the compatibility layer:
GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();Enabling the compatibility layer provides the following features:
- Tweaks the internal expression builder for Entity Framework compatibility
- EF query optimization
- EF ServiceProvider caching support
- Creates parameterized queries
DECLARE @__Value_0 nvarchar(4000) = N'vahid';
SELECT [u].[Id], [u].[CreateDate], [u].[FkGuid], [u].[Name]
FROM [Users] AS [u]
WHERE [u].[Name] = @__Value_0Setting this property to true Enables the EntityFramework Compatibility layer to make the generated expressions compatible with entity framework.
- type:
bool - default:
false
Simply sets the EntityFrameworkCompatibilityLayer property to true.
Simply sets the EntityFrameworkCompatibilityLayer property to false.
When using composite maps with Entity Framework (especially PostgreSQL), follow these guidelines for optimal compatibility:
::: warning Guid Properties
// ✅ Recommended for EF
mapper.AddCompositeMap("search",
x => x.FkGuid.ToString(), // Convert to string
x => x.Name);
// ❌ Not recommended for EF (may cause translation issues)
mapper.AddCompositeMap("search",
x => (object)x.FkGuid,
x => x.Name);:::
::: warning Numeric Properties
// ✅ Recommended for EF
mapper.AddCompositeMap("search",
x => x.Name,
x => x.Id.ToString()); // Convert to string
// ❌ Not recommended for EF (may cause type mismatch)
mapper.AddCompositeMap("search",
x => x.Name,
x => (object)x.Id);:::
::: warning DateTime Properties (PostgreSQL)
// ✅ Required for PostgreSQL
var mapper = new GridifyMapper<User>(cfg => cfg.DefaultDateTimeKind = DateTimeKind.Utc)
.AddCompositeMap("search",
x => x.Name,
x => (object)x.CreateDate);
// ❌ Without UTC configuration, PostgreSQL will throw an error:::
- Use
.ToString()for type consistency - When combining different property types (string, numeric, Guid), convert them all to strings - Set UTC DateTimeKind for PostgreSQL - Configure
DefaultDateTimeKind = DateTimeKind.Utcwhen working with DateTime properties - Test with
.ToQueryString()- Verify EF can translate your expressions to SQL:var sql = dbContext.Users .ApplyFiltering("search=value", mapper) .ToQueryString();
- Keep types homogeneous - When possible, map properties of the same type together for better performance