当前位置: 首页>>代码示例>>C#>>正文


C# Internal.LazyInternalConnection类代码示例

本文整理汇总了C#中System.Data.Entity.Internal.LazyInternalConnection的典型用法代码示例。如果您正苦于以下问题:C# LazyInternalConnection类的具体用法?C# LazyInternalConnection怎么用?C# LazyInternalConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LazyInternalConnection类属于System.Data.Entity.Internal命名空间,在下文中一共展示了LazyInternalConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Can_replace_connection_implementation

        private void Can_replace_connection_implementation(
            ReplaceConnectionContext context,
            LazyInternalConnection newConnection)
        {
            Database.Delete(newConnection.Connection);
            Database.Delete(typeof(ReplaceConnectionContext).DatabaseName());

            context.InternalContext.OverrideConnection(newConnection);

            context.Entities.Add(
                new PersistEntity
                {
                    Name = "Testing"
                });
            context.SaveChanges();

            Assert.Same(newConnection.Connection, context.Database.Connection);
            Assert.True(Database.Exists(newConnection.Connection));
            Assert.False(Database.Exists(typeof(ReplaceConnectionContext).DatabaseName()));

            // By pass EF just to make sure everything targetted the correct database
            var cmd = newConnection.Connection.CreateCommand();
            cmd.CommandText = "SELECT Count(*) FROM PersistEntities";
            cmd.Connection.Open();
            Assert.Equal(1, cmd.ExecuteScalar());
            cmd.Connection.Close();
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:27,代码来源:DbContextTests.cs

示例2: Name_of_context_with_namespace_stripped_is_found_in_app_config

        public void Name_of_context_with_namespace_stripped_is_found_in_app_config()
        {
            using (var internalConnection = new LazyInternalConnection("Couger35.Hubcap.ShortNameDbContext"))
            {
                var connection = internalConnection.Connection;

                Assert.Equal("ShortNameInAppConfig", connection.Database);
                Assert.IsType<SqlConnection>(connection);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs

示例3: Full_name_of_context_is_found_in_app_config

        public void Full_name_of_context_is_found_in_app_config()
        {
            using (var internalConnection = new LazyInternalConnection("Couger35.Hubcap.FullNameDbContext"))
            {
                var connection = internalConnection.Connection;

                Assert.Equal("FullNameInAppConfig", connection.Database);
                Assert.IsType<SqlConnection>(connection);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs

示例4: Name_of_context_with_DbContext_stripped_is_not_found_in_app_config

        public void Name_of_context_with_DbContext_stripped_is_not_found_in_app_config()
        {
            using (var internalConnection = new LazyInternalConnection("Couger35.Hubcap.FullNameDbStrippedDbContext"))
            {
                var connection = internalConnection.Connection;

                Assert.Equal("Couger35.Hubcap.FullNameDbStrippedDbContext", connection.Database);
                Assert.IsType<SqlConnection>(connection);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs

示例5: Can_replace_connection

 public void Can_replace_connection()
 {
     using (var context = new ReplaceConnectionContext())
     {
         using (var newConnection = new LazyInternalConnection(
             context,
             new DbConnectionInfo(
                 SimpleConnectionString("NewReplaceConnectionContextDatabase"),
                 "System.Data.SqlClient")))
         {
             Can_replace_connection_implementation(context, newConnection);
         }
     }
 }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:14,代码来源:DbContextTests.cs

示例6: Can_replace_connection_with_different_provider

 public void Can_replace_connection_with_different_provider()
 {
     using (var context = new ReplaceConnectionContext())
     {
         using (var newConnection = new LazyInternalConnection(
             context,
             new DbConnectionInfo(
                 "Data Source=NewReplaceConnectionContextDatabase.sdf",
                 "System.Data.SqlServerCe.4.0")))
         {
             Can_replace_connection_implementation(context, newConnection);
         }
     }
 }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:14,代码来源:DbContextTests.cs

示例7: using

        public void LazyInternalConnection_can_calculate_ConnectionHasModel_true_from_connection_string_without_initializing()
        {
            var efString = ConfigurationManager.ConnectionStrings["EntityConnectionString"].ConnectionString;

            using (var connection = new LazyInternalConnection(efString))
            {
                Assert.True(connection.ConnectionHasModel);
                Assert.False(connection.IsInitialized);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs

示例8: LazyInternalConnection_can_calculate_ConnectionHasModel_true_from_config_file_without_initializing

 public void LazyInternalConnection_can_calculate_ConnectionHasModel_true_from_config_file_without_initializing()
 {
     using (var connection = new LazyInternalConnection("name=EntityConnectionString"))
     {
         Assert.True(connection.ConnectionHasModel);
         Assert.False(connection.IsInitialized);
     }
 }
开发者ID:junxy,项目名称:entityframework,代码行数:8,代码来源:InternalConnectionTests.cs

示例9: LazyInternalConnection_can_calculate_ConnectionHasModel_false_from_convention_without_initializing

 public void LazyInternalConnection_can_calculate_ConnectionHasModel_false_from_convention_without_initializing()
 {
     using (var connection = new LazyInternalConnection("MyName"))
     {
         Assert.False(connection.ConnectionHasModel);
         Assert.False(connection.IsInitialized);
     }
 }
开发者ID:junxy,项目名称:entityframework,代码行数:8,代码来源:InternalConnectionTests.cs

示例10: LazyInternalConnection_can_create_connection_from_DbConnectionInfo_from_overridden_config_file

        public void LazyInternalConnection_can_create_connection_from_DbConnectionInfo_from_overridden_config_file()
        {
            using (var connection = new LazyInternalConnection(new DbConnectionInfo("LazyConnectionTest")))
            {
                connection.AppConfig =
                    new AppConfig(
                        CreateEmptyConfig().AddConnectionString(
                            "LazyConnectionTest", "Database=FromOverridenConfig", "System.Data.SqlClient"));

                Assert.IsType<SqlConnection>(connection.Connection);
                Assert.Equal("FromOverridenConfig", connection.Connection.Database);
                Assert.Equal("LazyConnectionTest", connection.ConnectionStringName);
                Assert.Equal(DbConnectionStringOrigin.DbContextInfo, connection.ConnectionStringOrigin);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:15,代码来源:InternalConnectionTests.cs

示例11: Connection_from_factory_is_cached

        public void Connection_from_factory_is_cached()
        {
            using (var internalConnection = new LazyInternalConnection("NameForFactory"))
            {
                var connection = internalConnection.Connection;

                Assert.Same(connection, internalConnection.Connection);
                Assert.Same(connection, internalConnection.Connection);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs

示例12: LazyInternalConnection_provider_name_calculated_when_connection_by_convention

 public void LazyInternalConnection_provider_name_calculated_when_connection_by_convention()
 {
     using (var connection = new LazyInternalConnection("ConnectionName"))
     {
         Assert.Equal("System.Data.SqlClient", connection.ProviderName);
     }
 }
开发者ID:junxy,项目名称:entityframework,代码行数:7,代码来源:InternalConnectionTests.cs

示例13: LazyInternalConnection_can_calculate_ConnectionHasModel_true_after_initializing

        public void LazyInternalConnection_can_calculate_ConnectionHasModel_true_after_initializing()
        {
            using (var connection = new LazyInternalConnection("name=EntityConnectionString"))
            {
                var x = connection.Connection;
                Assert.True(connection.IsInitialized);

                Assert.True(connection.ConnectionHasModel);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs

示例14: Explicit_name_is_used_without_stripping_DbContext

        public void Explicit_name_is_used_without_stripping_DbContext()
        {
            using (var internalConnection = new LazyInternalConnection("Couger35.Hubcap.NameForFactoryDbContext"))
            {
                var connection = internalConnection.Connection;

                Assert.Equal("Couger35.Hubcap.NameForFactoryDbContext", connection.Database);
                Assert.IsType<SqlConnection>(connection);
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs

示例15: Disposed_LazyInternalConnection_can_be_reused

        public void Disposed_LazyInternalConnection_can_be_reused()
        {
            var internalConnection = new LazyInternalConnection("NameForFactory");
            try
            {
                var disposed1 = 0;
                var disposed2 = 0;

                var connection1 = internalConnection.Connection;
                connection1.Disposed += (_, __) => disposed1++;

                internalConnection.Dispose();
                Assert.Equal(1, disposed1);
                Assert.Equal(0, disposed2);

                var connection2 = internalConnection.Connection;
                connection2.Disposed += (_, __) => disposed2++;

                internalConnection.Dispose();
                Assert.Equal(1, disposed1);
                Assert.Equal(1, disposed2);
            }
            finally
            {
                internalConnection.Dispose();
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:27,代码来源:InternalConnectionTests.cs


注:本文中的System.Data.Entity.Internal.LazyInternalConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。