• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Internal.LazyInternalConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Connection_created_from_factory_is_disposed_after_use

 public void Connection_created_from_factory_is_disposed_after_use()
 {
     var disposed = false;
     using (var internalConnection = new LazyInternalConnection("NameForFactory"))
     {
         var connection = internalConnection.Connection;
         connection.Disposed += (_, __) => disposed = true;
     }
     Assert.True(disposed);
 }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs


示例17: Connection_created_from_hard_coded_connection_string_is_disposed_after_use

 public void Connection_created_from_hard_coded_connection_string_is_disposed_after_use()
 {
     var disposed = false;
     using (var internalConnection = new LazyInternalConnection("Database=HardCodedConnectionString"))
     {
         var connection = internalConnection.Connection;
         connection.Disposed += (_, __) => disposed = true;
     }
     Assert.True(disposed);
 }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs


示例18: Connection_created_from_app_config_is_disposed_after_use

 public void Connection_created_from_app_config_is_disposed_after_use()
 {
     var disposed = false;
     using (var internalConnection = new LazyInternalConnection("Couger35.Hubcap.FullNameDbContext"))
     {
         var connection = internalConnection.Connection;
         connection.Disposed += (_, __) => disposed = true;
     }
     Assert.True(disposed);
 }
开发者ID:junxy,项目名称:entityframework,代码行数:10,代码来源:InternalConnectionTests.cs


示例19: Changed_default_connection_factory_that_results_in_null_connections_throws

 public void Changed_default_connection_factory_that_results_in_null_connections_throws()
 {
     var existingFactory = DefaultConnectionFactoryResolver.Instance.ConnectionFactory;
     try
     {
         DefaultConnectionFactoryResolver.Instance.ConnectionFactory = new Mock<IDbConnectionFactory>().Object;
         using (var internalConnection = new LazyInternalConnection("NameNotInAppConfig"))
         {
             Assert.Equal(
                 Strings.DbContext_ConnectionFactoryReturnedNullConnection,
                 Assert.Throws<InvalidOperationException>(() => { var _ = internalConnection.Connection; }).Message);
         }
     }
     finally
     {
         DefaultConnectionFactoryResolver.Instance.ConnectionFactory = existingFactory;
     }
 }
开发者ID:junxy,项目名称:entityframework,代码行数:18,代码来源:InternalConnectionTests.cs


示例20: LazyInternalConnection_can_calculate_ConnectionHasModel_false_after_initializing

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

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Migrations.DbMigrator类代码示例发布时间:2022-05-26
下一篇:
C# Interception.DbConnectionInterceptionContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap