C# 无法按照教程进行操作:连接到数据存储[11/18]|初学者';s系列到:使用mongoDB的Web API

C# 无法按照教程进行操作:连接到数据存储[11/18]|初学者';s系列到:使用mongoDB的Web API,c#,.net,mongodb,asp.net-web-api,asp.net-core-webapi,C#,.net,Mongodb,Asp.net Web Api,Asp.net Core Webapi,我是monngoDB的初学者,刚刚创建了一个ASP.NETWebAPI来在MongoDB数据库中执行CRUD操作。我已经能够根据以下Microsoft教程创建一个简单的应用程序: 在本教程中,我无法理解,也不知道上面的代码 MongoDatabaseOptions.cs 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Threading.Tasks; 名称空间contosocipes.Models { 公共类MongoDat

我是monngoDB的初学者,刚刚创建了一个ASP.NETWebAPI来在MongoDB数据库中执行CRUD操作。我已经能够根据以下Microsoft教程创建一个简单的应用程序:

在本教程中,我无法理解,也不知道上面的代码

MongoDatabaseOptions.cs

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
名称空间contosocipes.Models
{
公共类MongoDatabaseOptions
{
}
}
IRecipeDataStore.cs

使用ContosoRecipes.Models;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
命名空间ContosoRecipes.Data
{
公共接口IRecipeDataStore
{
任务GetRandomRecipes(整数计数);
任务GetRecipeById(字符串id);
任务GetRecipesById(字符串ID);
任务搜索配方(字符串[]成分);
任务searchByTags(字符串[]标记);
任务更新方案(配方);
TaskRemoveRecipe(字符串配方\u id);
}
}
MongoRecipeDataStore.cs

使用ContosoRecipes.Models;
使用Microsoft.Extensions.Options;
使用MongoDB.Driver;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
命名空间ContosoRecipes.Data
{
公共类MongoRecipeDataStore:IRecipeDataStore
{
公共MongoRecipeDataStore(IMongoClient mongoClient、IOptions MongoDB选项、IMongoDatabase数据库)
{
}
公共异步任务GetRandomRecipes(整数计数)
{
抛出新的NotImplementedException();
}
公共异步任务GetRecipeById(字符串id)
{
抛出新的NotImplementedException();
}
公共异步任务GetRecipesById(字符串ID)
{
抛出新的NotImplementedException();
}
公共异步任务删除类型(字符串配方\u id)
{
抛出新的NotImplementedException();
}
公共异步任务searchRecipesByComponents(字符串[]成分)
{
抛出新的NotImplementedException();
}
公共任务SearchRecipesByTags(字符串[]标记)
{
抛出新的NotImplementedException();
}
公共任务更新配方(配方)
{
抛出新的NotImplementedException();
}
}
}
还有一点 ServiceCollectionExtensions.cs

使用Microsoft.Extensions.Configuration;
使用Microsoft.Extensions.DependencyInjection;
使用MongoDB.Bson.Serialization;
使用MongoDB.Bson.Serialization.Conventions;
使用MongoDB.Driver;
使用ContosoRecipes.Models;
名称空间中心配方
{
公共静态类ServiceCollectionExtensions
{
公共静态IServiceCollection AddMongoDb(此IServiceCollection服务,IConfiguration配置)
{
Configure(config.GetSection(“MongoDatabase”);
AddSingleton(provider=>newMongoClient(config[“MongoDatabase]”));
var pack=新约定包();
pack.Add(新的CamelCaseElementNameConvention());
Register(“自定义约定”,pack,t=>true);
BsonClassMap.RegisterClassMap(cm=>
{
cm.AutoMap();
cm.SetIdMember(cm.GetMemberMap(c=>c.Title));
});
返回服务;
}
}
}
我只是在Github上创建了一个存储库:


也许有人可以帮助,并为回购协议做出贡献,这将非常有帮助,非常感谢。

您尝试过吗?是的,已经尝试过这个,只是为它创建了一个:,但仍然缺少上面的某些部分。。