Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingMethodException: Method not found: SetConvertExpression #378

Closed
code-lime opened this issue Mar 2, 2024 · 1 comment · Fixed by #380
Closed

MissingMethodException: Method not found: SetConvertExpression #378

code-lime opened this issue Mar 2, 2024 · 1 comment · Fixed by #380
Assignees
Labels
bug Something isn't working

Comments

@code-lime
Copy link

code-lime commented Mar 2, 2024

If execute Linq2DB method

public async Task<T> GetAsync(CancellationToken cancellationToken)
{
    Memory? memory = await context.Memories.FirstOrDefaultAsync(v => v.Key == key, cancellationToken); <--
    if (memory is null) return defaultValue;
    return JsonSerializer.Deserialize<T>(memory.Value) ?? defaultValue;
}

throw error

System.MissingMethodException: Method not found: 'Void LinqToDB.Mapping.MappingSchema.SetConvertExpression(System.Type, System.Type, System.Linq.Expressions.LambdaExpression, Boolean)'.
   at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsImplDefault.<>c__DisplayClass14_0.<DefineConvertors>g__MapEFCoreType|1(Type modelType)
   at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsImplDefault.DefineConvertors(MappingSchema mappingSchema, IModel model, IValueConverterSelector convertorSelector, DataOptions dataOptions)
   at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsImplDefault.CreateMappingSchema(IModel model, IMetadataReader metadataReader, IValueConverterSelector convertorSelector, DataOptions dataOptions)
   at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsImplDefault.<>c__DisplayClass17_0.<GetMappingSchema>b__0(ICacheEntry e)
   at Microsoft.Extensions.Caching.Memory.CacheExtensions.GetOrCreate[TItem](IMemoryCache cache, Object key, Func`2 factory)
   at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsImplDefault.GetMappingSchema(IModel model, IMetadataReader metadataReader, IValueConverterSelector convertorSelector, DataOptions dataOptions)
   at LinqToDB.EntityFrameworkCore.LinqToDBForEFTools.GetMappingSchema(IModel model, IInfrastructure`1 accessor, DataOptions dataOptions)
   at LinqToDB.EntityFrameworkCore.LinqToDBForEFTools.CreateLinqToDBContext(DbContext context, IDbContextTransaction transaction)
   at LinqToDB.EntityFrameworkCore.LinqToDBForEFTools.ToLinqToDBTable[T](DbSet`1 dbSet)
   at A2Core.Infrastructure.DataBase.ApplicationDbContext.A2Core.Application.Common.Interfaces.IContext.get_Memories() in C:\GitHub\StudiaA2\a2-core\src\a2\A2Core.Infrastructure\DataBase\ApplicationDbContext.cs:line 30
   at A2Core.Infrastructure.DataBase.MemoryRepository.MemoryProperty`1.GetAsync(CancellationToken cancellationToken) in C:\GitHub\StudiaA2\a2-core\src\a2\A2Core.Infrastructure\DataBase\MemoryRepository.cs:line 20
   at A2Core.Infrastructure.Listeners.BePaidPaymentListener.DoScopeTickAsync(IServiceProvider provider, Boolean isHandle, CancellationToken cancellationToken) in C:\GitHub\StudiaA2\a2-core\src\a2\A2Core.Infrastructure\Listeners\BePaidPaymentListener.cs:line 43
   at A2Core.Infrastructure.Listeners.BaseScopeLoopSerivce.DoTickAsync(Boolean isHandle, CancellationToken cancellationToken) in C:\GitHub\StudiaA2\a2-core\src\a2\A2Core.Infrastructure\Listeners\BaseScopeLoopSerivce.cs:line 15
   at A2Core.Infrastructure.Listeners.BaseScopeLoopSerivce.DoTickAsync(Boolean isHandle, CancellationToken cancellationToken) in C:\GitHub\StudiaA2\a2-core\src\a2\A2Core.Infrastructure\Listeners\BaseScopeLoopSerivce.cs:line 15
   at A2Core.Infrastructure.Listeners.BaseLoopSerivce.DoLoopAsync(CancellationToken cancellationToken) in C:\GitHub\StudiaA2\a2-core\src\a2\A2Core.Infrastructure\Listeners\BaseLoopSerivce.cs:line 36

DbContext:

public partial class ApplicationDbContext : DbContext, IContext
{
    public ApplicationDbContext() { }
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
    // -- ANY CODE --
    public DbSet<Memory> Memories { get; set; }
    // -- ANY CODE --
    ITable<Memory> IContext.Memories => Memories.ToLinqToDBTable(); <-- ERROR
    // -- ANY CODE --
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // -- ANY CODE --
        modelBuilder
            .Entity<Memory>(entity =>
            {
                entity.ToTable("memories");

                entity.HasKey(e => e.Key);

                entity.Property(e => e.Key);
                entity.Property(e => e.Value);
            });
        // -- ANY CODE --
    }
    // -- ANY CODE --
}

Method LinqToDBForEFTools.Initialize(); executed before setup DB

Relevant Nuget Packages:

  • linq2db.EntityFrameworkCore: v8.0.0
  • Pomelo.EntityFrameworkCore.MySql: v8.0.1
@MaceWindu
Copy link
Contributor

As workaround downgrade linq2db to 5.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants