yv989c / BlazarTech.QueryableValues

This library allows you to efficiently compose an IEnumerable<T> in your Entity Framework Core queries when using the SQL Server database provider.
Other
90 stars 6 forks source link

ToQueryString does not work #29

Closed denadmin closed 1 year ago

denadmin commented 1 year ago

I got an issue, while trying to read a query plain text

Min example:

using BlazarTech.QueryableValues;
using Microsoft.EntityFrameworkCore;

var dbContext = new ApplicationContext();
var codes = new[] { 1, 2 };

var query = dbContext.Docs
    .Where(x => dbContext.AsQueryableValues(codes).Contains(x.Id));

Console.WriteLine(query.ToQueryString());
public class doc
{
    public int Id { get; set; }
}
public class ApplicationContext : DbContext
{
    public DbSet<doc> Docs { get; set; }
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(
            "..........",
            o => o.UseQueryableValues());
    }
}

The example above throws an exception:

System.InvalidCastException: Unable to cast object of type 'BlazarTech.QueryableValues.DeferredInt32Values' to type 'System.String'.

Enviroment: BlazarTech.QueryableValues 1.0.9 .net 7.0.202 ef core 7.0.4

yv989c commented 1 year ago

Hi @denadmin,

This is a know issue caused by https://github.com/dotnet/efcore/issues/30515. I implemented a workaround for it.

Let me know if that helps.

denadmin commented 1 year ago

@yv989c thanks for quick reply, that's do the thing