Closed romainecarter closed 6 years ago
Unfortunately no,
You can use EF+ Query Filter but it doesn't work as good as this library for by example Tenant
scenario.
Let me know if that successfully answer your question.
Best Regards,
Jonathan
Help us to support this library: Donate
Thanks I will look into EF + Query Filter.
Below example the filter is not added, is this one of the limitations you mentioned?
using System;
using System.Data.Entity;
using System.Linq;
using Z.EntityFramework.Plus;
namespace DbContextAOP
{
class Program
{
static void Main(string[] args)
{
QueryFilterManager.Filter<Employee>(q => q.Where(x => x.BusinessEntityID == 250));
using (var db = new AdventureWorks2016CTP3Entities())
{
var purchase = db.PurchaseOrderHeader.Include(a=>a.Employee).Select(i => i.Freight + " " + i.Employee.BusinessEntityID);
foreach (var m in purchase)
{
Console.WriteLine(m);
}
}
}
}
}
Generated SQL
SELECT
CAST( [Extent1].[Freight] AS nvarchar(max)) + N' ' + CAST( [Extent1].[EmployeeID] AS nvarchar(max)) AS [C1]
FROM [Purchasing].[PurchaseOrderHeader] AS [Extent1]
Hello @romainecarter ,
I believe you are missing the QueryFilterManager.InitializeGlobalFilter(ctx);
code.
Global filter is not applied by default. It's normally recommended to add it in your context constructor if you can.
Best Regards,
Jonathan
Help us to support this library: Donate
Thanks @JonathanMagnan , I added that but getting the same results.
Seems adding a navigation property to the query as in the above example does not work and the where clause is dropped in the generated SQL.
Hmmm,
Looking at the source code, we only support filtering list but recently, we added a new property QueryFilterManager.AllowPropertyFilter = true;
which also to support navigation property that is not list but item.
Could you try with this option?
Best Regards,
Jonathan
Help us to support this library: Donate
That worked!
Based on the documentation I see where the filters are configured through OnModelCreating override, Is there a way to do this using Database first?