Open blackWins opened 3 months ago
Thanks for reporting with the example code, I'll check it asap
It's probably happened after PR https://github.com/enisn/AutoFilterer/pull/69
Hand-written query expression is compiled as filter.CreateTime.Min <= Convert(x.CreateTime, Nullable'1)
instead x.CreateTime >= 2023-08-12 3:17:30 PM
It's probably a Nullable check problem. I'll work on it
It works with SqlServer provider, can you provide me which Entity Framework provider do you use in this case?
SqlServer
MyAbpEntityFrameworkCoreModule.cs
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<ManageDbContext>(options =>
{
options.AddDefaultRepositories(includeAllEntities: true);
});
context.Services.AddAbpDbContext<MyAbpDbContext>(options =>
{
options.AddDefaultRepositories(includeAllEntities: true);
});
Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
}
ManageDbContext
[ConnectionStringName("manage")]
public class ManageDbContext: AbpDbContext<ManageDbContext>
{
public ManageDbContext(DbContextOptions<ManageDbContext> options)
: base(options)
{
}
public DbSet<ProjectInfo> ProjectInfos { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<ProjectInfo>(b =>
{
b.ToTable(MyAbpConsts.DbTablePrefix + "ProjectInfo");
b.ConfigureByConvention();
});
}
}
ProjectInfoAppService
public class ProjectInfoAppService : CrudAppService<ProjectInfo, ProjectInfoDto, Guid, ProjectInfoGetListInput, CreateUpdateProjectInfoDto, CreateUpdateProjectInfoDto>, IProjectInfoAppService
{
public ProjectInfoAppService(IRepository<ProjectInfo, Guid> repository) : base(repository)
{
}
protected override async Task<IQueryable<ProjectInfo>> CreateFilteredQueryAsync(ProjectInfoGetListInput input)
{
return (await base.CreateFilteredQueryAsync(input)).ApplyFilter(input);
}
}
Here's the problem .0000000
SELECT COUNT(*)
FROM [StockInfo] AS [s]
WHERE CASE
WHEN [s].[CreateTime] >= '2024-06-01T00:00:00.0000000' THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END & CASE
WHEN [s].[CreateTime] <= '2024-06-29T00:00:00.0000000' THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END = CAST(1 AS bit)
It's generated by the EF Core provider. AutoFilterer doesn't generate SQL queries. It generates only LINQ expressions.
Does it work when you write it manually like below?
.Where(x => x.CreationTime <= DateTime.Now)
.Where(x => x.CreationTime <= DateTime.Now)
The execution was successful
protected override async Task<IQueryable<StockInfo>> CreateFilteredQueryAsync(StockInfoGetListInput input)
{
return (await base.CreateFilteredQueryAsync(input))
.Where(x => x.CreateTime > input.CreateTime.Min && x.CreateTime < input.CreateTime.Max);
//.ApplyFilter(input);
}
Which AutoFilterer version are you currently using? This has to be parameterized after PR #59
3.0.0
This issue occurs in sqlserver 2016
Exception occurred when using range filtering
Project information:abp v8.1.3
filter model