MissingMethodException DbSet.ToList

编程入门 行业动态 更新时间:2024-10-09 21:24:06
本文介绍了MissingMethodException DbSet.ToList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的Entity Framework Core项目中,我有一个通用存储库,该存储库具有 GetAll()方法

On my Entity Framework Core project I've a generic repository with a GetAll() method

public ICollection<Entity> GetAll(){ return DbSet.ToList(); }

但是当我执行它时,抛出以下内容:

But when I execute it, throws the following:

System.MissingMethodException was unhandled HResult=-2146233069 Message=Method not found: 'Void Microsoft.EntityFrameworkCore.Query.QueryContextFactory..ctor(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IStateManager, Microsoft.EntityFrameworkCore.Internal.IConcurrencyDetector, Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IChangeDetector)'. Source=Microsoft.EntityFrameworkCore.Relational StackTrace: at Microsoft.EntityFrameworkCore.Query.Internal.RelationalQueryContextFactory..ctor(IStateManager stateManager, IConcurrencyDetector concurrencyDetector, IRelationalConnection connection, IChangeDetector changeDetector) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.<>c.<AddQuery>b__1_1(IServiceProvider p) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor) at Microsoft.EntityFrameworkCore.DbContext.get_QueryProvider() at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.<.ctor>b__3_0() at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value() at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IEnumerable<TEntity>.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at DataAccessLayer.Repositories.BaseRepository`1.GetAll() in D:\TFS-LocalVersions\tourstop\Service\Musical.Broccoli.API\src\DataAccessLayer\Repositories\BaseRepository.cs:line 30 at Testing.Program.Main(String[] args) in D:\TFS-LocalVersions\tourstop\Service\Musical.Broccoli.API\Testing\Program.cs:line 40 InnerException

正在注入 DbContext ,我可以添加注册表,但是不能执行ToList().

The DbContext is being inject and I can add registries, but cannot do a ToList().

我的 DbContext 是

public class Context : DbContext { public Context(DbContextOptions<Context> options) : base(options) { } public DbSet<Entity> Addresses { get; set; }

存储库构造函数:

public BaseRepository(Context context) { this.Context = context; this.DbSet = this.Context.Set<Entity>(); }

并且正在使用默认的DI注入

And is being injected with the default DI

project.json如下:

The project.json is the following:

{ "version": "1.0.0-*", "dependencies": { "MySql.Data.EntityFrameworkCore": "7.0.6-IR31", "MySql.Data": "7.0.6-IR31", "Common": "1.0.0-*", "Microsoft.EntityFrameworkCore": "1.1.0", "NETStandard.Library": "1.6.1" }, "frameworks": { "netstandard1.6": { "imports": "dnxcore50" } } }

有人对为什么以及如何解决有任何想法吗?

Does someone has any ideas on why, and how to solve it?

推荐答案

尝试删除"Microsoft.EntityFrameworkCore":"1.1.0"来自project.json

Try to remove "Microsoft.EntityFrameworkCore": "1.1.0" from project.json

更多推荐

MissingMethodException DbSet.ToList

本文发布于:2023-11-12 13:04:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MissingMethodException   DbSet   ToList

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!