Custom Filter not working in EF 6
See original GitHub issueI try to implement a custom filter in my multi dbcontext and not work correctly, I try to implement in a fresh solution but I have the same error (ABP version 4.2 / MVC / AngularJs) Here is my code
public interface IMustHaveCompany
{
long CompanyId { get; set; }
}
public class Person : FullAuditedEntity, IMustHaveCompany
{
public long CompanyId { get; set; }
public string Name { get; set; }
}
// On coreModule -> PreInitialize()
...
Configuration.UnitOfWork.RegisterFilter("CompanyFilter", true);
// On DbContext Class
public override void Initialize()
{
base.Initialize();
// If I uncomment this the stack say me
// System.ApplicationException: Filter name CompanyFilter not found
//this.SetFilterScopedParameterValue(
// "CompanyFilter",
// "companyId",
// 2);
}
protected void OnodelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Filter("CompanyFilter",
(IMustHaveCompany entity, int companyId) => entity.CompanyId == companyId, () =>
{
return 19;
});
}
// I try to call on TenantDashboardAppService
CurrentUnitOfWork.SetFilterParameter("CompanyFilter", "CompanyId", 19);
var q = _personManager.Persons.ToArray();
public interface IPersonManager : IDomainService
{
IQueryable<Person> Persons { get; }
}
public class PersonManager : demoServiceBase, IPersonManager
{
private readonly IRepository<Person> _repository;
public PersonManager(IRepository<Person> repository)
{
_repository = repository;
}
public virtual IQueryable<Person> Persons
{
get { return _repository.GetAll(); }
}
}
What is wrong??? When I look on Configuration.UnitOfWork the filter is regitered on PreInit with 0 parameter, but it’s the same for tenant May/Must
Issue Analytics
- State:
- Created 5 years ago
- Comments:26 (10 by maintainers)
Top Results From Across the Web
EF 6 - can not use string in filter when querying
Well, it seems the answer to this issue is using ObjectQuery from ObjectContext. However, this seems a little confusing to me.
Read more >How To Add Custom Data Filter in EF Core
In this article, I will explain how to add a custom data filter in Entity Framework Core. We will create a filter for...
Read more >Tutorial: Add sorting, filtering, and paging with the Entity ...
In this tutorial you add sorting, filtering, and paging functionality to the **Students** Index page. You also create a simple grouping ...
Read more >How to filter entities not contained from an existing list with ...
Filtering entities by excluding all items from an existing list can sometimes be very useful. For example, you deserialize a JSON file into ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No problem, I will try to reproduce it. It should be easy.
Thank you for your attention. I may figured it out.the
GetCurrentUsersOuIdOrNull
only takes the value from claims. It should checkCurrentUnitOfWorkProvider.Current.Filters
firstly.