I've following class setting:
public class Result
{
public int Value { get; set; }
public string Name { get; set; }
}
public class ResultExtended : Result
{
public int CustomerId { get; set; }
}
When I use following call using the filter option
var query = _provider.Get<Address>()
.Where(a => a.ID > 10)
.Select(a => new ResultExtended { CustomerId = a.County, Name = a.City });
var options = new TestLoadOptions
{
Skip = 0,
Take = 10,
Filter = new List<object> { "Name", "contains", "test" }
};
var result = DataSourceLoader.Load(query, options);
The resulting query looks like
from Address a in Query(CHG.Demo.Objects.Address) where ([a].ID > 10) where new ResultExtended() {CustomerId = [a].County, Name = [a].City}.Name.ToLower().Contains("test") select new ResultExtended() {CustomerId = [a].County, Name = [a].City} => Take(10)
But when I express the same query "directly"
var query = _provider.Get<Address>()
.Where(a => a.ID > 10)
.Select(dto => new ResultExtended { CustomerId = dto.County, Name = dto.City })
.Where(obj => obj.Name.ToLower().Contains("test"))
.Take(10);
var result = query.ToList();
the resulting query is correct
from Address a in Query(CHG.Demo.Objects.Address) where ([a].ID > 10) where [a].City.ToLower().Contains("test") select new ResultExtended() {CustomerId = [a].County, Name = [a].City} => Take(10)
I guess the expression builder if the DataSourceLoader
creates a wrong expression when applying the filter.
Update:
By comparing the two expression trees I found out that the MemberExpression obj.Name
are different. The MemberInfo of the first query says that the ReflectedType
is ResultExtended
, the value for the second query is Result
.
So when I call it
var result = DataSourceLoader.Load<Result>(query, options);
the error is gone.