![](/img/trans.png)
[英]How to deal with sorting for multiple Language in MongoDb asp.net core application using mongoDb C# driver
[英]How can I use the MongoDB Driver with C# ASP.NET Core API framework?
我正在尝试创建一个web api应用程序,它将从我已经存在的mongo数据库中获取结果,但是这样做时我收到此错误
Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
An unhandled exception occurred while processing the request.
TypeLoadException: Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
MongoDB.Driver.Core.Events.EventContext+AsyncLocal.get_Value()
MongoDB.Driver.Core.Events.EventContext+AsyncLocal.get_Value()
MongoDB.Driver.Core.Events.EventContext.BeginOperation(Nullable<long> operationId)
MongoDB.Driver.Core.Operations.FindCommandOperation.Execute(IReadBinding binding, CancellationToken cancellationToken)
MongoDB.Driver.Core.Operations.FindOperation.Execute(IReadBinding binding, CancellationToken cancellationToken)
MongoDB.Driver.OperationExecutor.ExecuteReadOperation<TResult>(IReadBinding binding, IReadOperation<TResult> operation, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl.ExecuteReadOperation<TResult>(IClientSessionHandle session, IReadOperation<TResult> operation, ReadPreference readPreference, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl.ExecuteReadOperation<TResult>(IClientSessionHandle session, IReadOperation<TResult> operation, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl.FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl+<>c__DisplayClass35_0.<FindSync>b__0(IClientSessionHandle session)
MongoDB.Driver.MongoCollectionImpl.UsingImplicitSession<TResult>(Func<IClientSessionHandle, TResult> func, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl.FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options, CancellationToken cancellationToken)
MongoDB.Driver.FindFluent.ToCursor(CancellationToken cancellationToken)
我目前有一个针对.NET Core 2.0的ASP.NET Core框架
这是从方法调用中抛出的
var documents = collection.Find(_ => true).ToList();
显然,从我所读到的远程开发还不支持.NET Core,但是在MongoDB网站( https://docs.mongodb.com/ecosystem/drivers/csharp/ )上它表示支持驱动程序版本2.4使用.NET Core 2.0。 我已经安装了2.4驱动程序版本,但我似乎无法使用.Find从数据库中取出任何东西。
有没有人有这个解决方案,因为我真的很喜欢我可以在Linux而不是Windows上使用的应用程序?
使用针对.NET Core 2.0的驱动程序绝对是可能的。 您只需要确保引用作为以下NuGet包的一部分提供的.NET Standard 1.5程序集:
https://www.nuget.org/packages/MongoDB.Driver
此外,新版本2.5几天前刚刚发布,可能最适合MongoDB 3.6。
您可能也想阅读本教程: http : //www.qappdesign.com/using-mongodb-with-net-core-webapi/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.