【问题标题】:MySQL equivalent of SQLite SQLiteConnectionContextMySQL 相当于 SQLite SQLiteConnectionContext
【发布时间】:2013-11-28 00:15:36
【问题描述】:

我想知道 SQLiteConnectionContext 类的 MySQL 等效项是什么。我需要这个才能为我的程序提供一个通用的连接上下文。我正在创建一个基于实体的解决方案,它将从 MySQL 数据库中推送和提取数据。如果有更好的方法可以做到这一点,我也对此持开放态度。下面是我正在寻找的 SQLite 版本。

/// <summary>
/// A ConnectionContext common for all of the Inventory project
/// </summary>
public class InventoryConnectionContext : SQLiteConnectionContext
{
    public InventoryConnectionContext(bool connect = true)
        : base(InventoryConnectionString, connect)
    {
    }

    /// <summary>
    /// Constructs a BudgetConnectionContext and optionally opens the connection
    /// </summary>
    /// <param name="connectString">Connection string that points to a connection aside from the default connection</param>
    /// <param name="connect">Specifies whether or not to open the connection</param>
    public InventoryConnectionContext(string connectString, bool connect = true)
        : base(connectString)
    {
        if (connect)
            Connect();
    }
}

【问题讨论】:

    标签: c# mysql entity-framework sqlite


    【解决方案1】:

    它们是在你放置它们的实体项目中的.edmx文件下动态生成的。它似乎遵循这种格式 *(nameofdb)*Entities 并且是一个可实例化的类。

    要生成它,您需要删除 EntityFrameWork、MySQL.Data、MySQL.Data.Entities NuGet,然后将您的服务器拉入。您可以通过单击 View->Server Explorer 然后右键单击 SharePoint Connections(可能命名略有不同)并以这种方式添加您的服务器。然后,您可以导入所有表和实体。它们将显示在 .tt 文件下,并且也是自动生成的可实例化类。通过知道您需要上下文和实体来修改数据库,所有这些都可以一起使用。 [上下文].[表格].添加/删除;一个例子context.test_table.Add(myEntity);

    ;tldr : 添加服务器,它在 .edmx 文件下显示为 .context.tt 以及其下的类。

    【讨论】:

      猜你喜欢
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      • 2014-08-01
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 2011-01-11
      相关资源
      最近更新 更多