小编Fla*_*ave的帖子

如何在代码中添加实体框架6提供程序?

我在C#应用程序中使用Entity Framework 6,它完美地运行.创建Model时,将生成app.config并具有所有必需的配置.现在我不喜欢app.config中的东西,所以我使用连接字符串构建器.我成功地删除了app.config文件中的所有内容,除了以下内容:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
</entityFramework>
Run Code Online (Sandbox Code Playgroud)

如果我删除它,它不起作用.那么如何将该配置转换为c#代码?我该怎么办?我查看了基于代码的配置(http://msdn.microsoft.com/en-us/data/jj680699)但是,它没有帮助.

我创建连接字符串的部分类看起来像这样:

public partial class LogEntities
    {
        public LogEntities(string serverName)
            : base(GetConnectionString(serverName))
        {
        }

        public static string GetConnectionString(string serverName)
        {
            // Specify the provider name, server and database.
            const string databaseName = "_LOG";

            // Initialize the connection string builder for the underlying provider.
            SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder
            {
                DataSource = serverName,
                InitialCatalog = databaseName,
                IntegratedSecurity = true,
                MultipleActiveResultSets = true
            }; …
Run Code Online (Sandbox Code Playgroud)

c# connection-string entity-framework-6

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

connection-string ×1

entity-framework-6 ×1