使用 .NET 在 mySQL 中保存机器人状态数据

Saving bot state data in mySQL with .NET

由于 Bot State 服务即将停用,我想将我的机器人状态信息存储在本地 mySQL 数据库中。

我尝试使用 mySQL 连接字符串在 Global.asax 中实例化 SqlBotDataStore 客户端,但我认为我遗漏了一些东西,因为 SqlBotDataEntities table 尚未创建。

请对此提出您的建议。谢谢!

protected void Application_Start(object sender, EventArgs e)
{
    {
        var config = GlobalConfiguration.Configuration;

        Conversation.UpdateContainer(
            builder =>
                {
                    builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));

                    var store = new SqlBotDataStore(ConfigurationManager.ConnectionStrings["mySQL_ConnectionString"].ConnectionString);

                    builder.Register(c => store)
                        .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                        .AsSelf()
                        .SingleInstance();


                    // Register your Web API controllers.
                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
                    builder.RegisterWebApiFilterProvider(config);

                });

        config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container);
    }

    // WebApiConfig stuff
    GlobalConfiguration.Configure(config =>
    {
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    });
}
https://github.com/Microsoft/BotBuilder-Azure/ 中的

SqlBotDataStore 是为 Azure SQL 制作的,而不是 MySQL。

您不能将它与 MySQL 数据库一起使用。

这个 NuGet 包有 2 个选项:

  • Azure Table 存储
  • CosmosDB