Представьте, что у меня есть два объекта
public class OrderLine : Identifiable
{
public Order Order {get;set;}
...
// other properties
}
public class Order : Identifiable
{
public Guid CompanyId { get; set;}
...
// other properties
}
Я хочу выполнить неявную фильтрацию (независимо от фильтра, созданного внешним интерфейсом). Я хочу фильтровать OrderLines по CompanyId, который находится не непосредственно в объекте, а в связанном родительском объекте.
Поэтому я реализую OnApplyFilter (существующий фильтр строки) , где мне нужен AttrAttribute для создания выражения и т. д. (как описано на веб-странице JsonApiDotnetCore).
public override FilterExpression? OnApplyFilter(FilterExpression? existingFilter)
{
// some initialization and Db fetching
AttrAttribute companyIdAttribute = ResourceType.Attributes
.Single(account => account.Property.Name == "Order.CompanyId");
//This does not work and I am wondering what to do...
// ...
// some logic
var exp = new ComparisonExpression(
ComparisonOperator.Equals,
new ResourceFieldChainExpression(companyIdAttribute),
new LiteralConstantExpression("some company id which signed user has access to"))
// rest of the method checking the filter and returning the appended `existingFilter` by my
// custom filter
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... t-property