【问题标题】:ServiceStack Ormlite usage in ServiceInterfaceServiceInterface 中的 ServiceStack Ormlite 使用
【发布时间】:2015-12-06 22:49:46
【问题描述】:

我使用空的 asp.net 模板创建了一个解决方案。 我添加了 Ormlite 和 MySql Servicestatck 库并在 Apphost.cs 中配置了它们

        ConnectionStringSettings connstring = ConfigUtils.GetConnectionStringSetting("Nice2NoConnection");
        container.Register<IDbConnectionFactory>(new OrmLiteConnectionFactory(connstring.ToString(), MySqlDialectProvider.Instance));


        // Below we refer to the connection factory that we just registered
        // with the container and use it to create our table(s).
        using (var db = container.Resolve<IDbConnectionFactory>().Open())
        {
            // We’re just creating a single table, but you could add
            // as many as you need.  Also note the “overwrite: false” parameter,
            // this will only create the table if it doesn’t already exist.
            db.CreateTable<Channel>(overwrite: false);

我无法弄清楚如何访问在 ServiceInterface 项目中包含 Save() 的 OrmliteWriteExtensions。我尝试在那里添加 Ormlite 和 MySql 但不知道如何访问该项目中连接工厂的引用。

我认为我的问题与对 IoC 缺乏更深入的了解有关 我可能在这里把事情复杂化了。

建议?

TIA

【问题讨论】:

    标签: c# mysql ormlite-servicestack


    【解决方案1】:

    感谢您的反馈。我要感谢你提供了这么棒的图书馆。我的问题原来是我对 IoC 缺乏了解,我不得不编写如下代码:var conn = HostContext.Container.Resolve<IDbConnection>(); conn.Open(); conn.Save<Channel>(channel);

    【讨论】:

      【解决方案2】:

      OrmLite 扩展方法位于 ServiceStack.OrmLite 命名空间下,因此您只需导入即可访问它们:

      using ServiceStack.OrmLite;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-05
        • 1970-01-01
        • 2013-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多