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


C# Data.DataConnection类代码示例

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


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

示例1: TestChar

        public void TestChar([IncludeDataContexts(CurrentProvider)] string context)
        {
            using (var conn = new DataConnection(context))
            {
                Assert.That(conn.Execute<char> ("SELECT Cast('1' as char)"),         Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT Cast('1' as char)"),         Is.EqualTo('1'));
                Assert.That(conn.Execute<char> ("SELECT Cast('1' as char(1))"),      Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT Cast('1' as char(1))"),      Is.EqualTo('1'));

                Assert.That(conn.Execute<char> ("SELECT @p",                  DataParameter.Char("p",  '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT @p",                  DataParameter.Char("p",  '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char> ("SELECT Cast(@p as char)",    DataParameter.Char("p",  '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT Cast(@p as char)",    DataParameter.Char("p",  '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char> ("SELECT Cast(@p as char(1))", DataParameter.Char("@p", '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT Cast(@p as char(1))", DataParameter.Char("@p", '1')), Is.EqualTo('1'));

                Assert.That(conn.Execute<char> ("SELECT @p", DataParameter.VarChar ("p", '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT @p", DataParameter.VarChar ("p", '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char> ("SELECT @p", DataParameter.NChar   ("p", '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT @p", DataParameter.NChar   ("p", '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char> ("SELECT @p", DataParameter.NVarChar("p", '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT @p", DataParameter.NVarChar("p", '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char> ("SELECT @p", DataParameter.Create  ("p", '1')), Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT @p", DataParameter.Create  ("p", '1')), Is.EqualTo('1'));

                Assert.That(conn.Execute<char> ("SELECT @p", new DataParameter { Name = "p", Value = '1' }), Is.EqualTo('1'));
                Assert.That(conn.Execute<char?>("SELECT @p", new DataParameter { Name = "p", Value = '1' }), Is.EqualTo('1'));
            }
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:29,代码来源:MySqlTest.cs

示例2: TearDown

 protected override void TearDown()
 {
     using (var dbManager = new DataConnection("PerformanceTest"))
         dbManager
             .SetCommand("TRUNCATE TABLE Simplests")
             .Execute();
 }
开发者ID:sdanyliv,项目名称:ormbattle,代码行数:7,代码来源:Linq2DbTest.cs

示例3: Test1

        public void Test1(string context)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;

            using (var conn = new DataConnection(SqlServerTools.GetDataProvider(), connectionString))
            {
                conn.SetCommand("SELECT 1");

                var rd = conn.Command.ExecuteReader();

                if (rd.Read())
                {
                    var dp   = conn.DataProvider;
                    var p    = Expression.Parameter(typeof(IDataReader));
                    var dr   = Expression.Convert(p, dp.DataReaderType);
                    var ex   = (Expression<Func<IDataReader,int,int>>)dp.GetReaderExpression(conn.MappingSchema, rd, 0, dr, typeof(int));
                    var func = ex.Compile();

                    do
                    {
                        var value = func(rd, 0);
                        Assert.AreEqual(1, value);
                    } while (rd.Read());
                }
                else
                {
                    Assert.Fail();
                }
            }
        }
开发者ID:jack128,项目名称:linq2db,代码行数:30,代码来源:ExpressionTest.cs

示例4: NorthwindDataContext

		[Test, NorthwindDataContext(true)] // SQLite returns Int64 for column instead of Int32
		public void Test1(string context)
		{
			var connectionString = DataConnection.GetConnectionString(context);
			var dataProvider     = DataConnection.GetDataProvider(context);


			using (var conn = new DataConnection(dataProvider, connectionString))
			{
				conn.InitCommand(CommandType.Text, "SELECT 1", null, null);

				var rd = conn.Command.ExecuteReader();

				if (rd.Read())
				{
					var dp   = conn.DataProvider;
					var p    = Expression.Parameter(typeof(IDataReader));
					var dr   = Expression.Convert(p, dp.DataReaderType);
					var ex   = (Expression<Func<IDataReader,int,int>>)dp.GetReaderExpression(conn.MappingSchema, rd, 0, dr, typeof(int));
					var func = ex.Compile();

					do
					{
						var value = func(rd, 0);
						Assert.AreEqual(1, value);
					} while (rd.Read());
				}
				else
				{
					Assert.Fail();
				}
			}
		}
开发者ID:ronnyek,项目名称:linq2db,代码行数:33,代码来源:ExpressionTests.cs

示例5: Test1

        public void Test1([IncludeDataContexts("Northwind")] string context)
        {
            using (var conn = new DataConnection(SqlServerFactory.GetDataProvider(), "Server=.;Database=Northwind;Integrated Security=SSPI"))
            {
                conn.SetCommand("SELECT 1");

                var rd = conn.Command.ExecuteReader();

                if (rd.Read())
                {
                    var dp   = conn.DataProvider;
                    var p    = Expression.Parameter(typeof(IDataReader));
                    var dr   = Expression.Convert(p, dp.DataReaderType);
                    var ex   = (Expression<Func<IDataReader,int,int>>)dp.GetReaderExpression(conn.MappingSchema, rd, 0, dr, typeof(int));
                    var func = ex.Compile();

                    do
                    {
                        var value = func(rd, 0);
                        Assert.AreEqual(1, value);
                    } while (rd.Read());
                }
                else
                {
                    Assert.Fail();
                }
            }
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:28,代码来源:ExpressionTest.cs

示例6: Test3

        public void Test3([IncludeDataContexts(
            ProviderName.SqlServer,
            ProviderName.SqlServer2008,
            ProviderName.SqlServer2008 + ".1",
            ProviderName.SqlServer2005,
            ProviderName.SqlServer2005 + ".1",
            ProviderName.Access
            )] string context)
        {
            using (var conn = new DataConnection(context))
            {
                Assert.That(conn.Connection.State,    Is.EqualTo(ConnectionState.Open));
                Assert.That(conn.ConfigurationString, Is.EqualTo(context));

                if (context.EndsWith(".2005"))
                {
                    var sdp = conn.DataProvider;
                    Assert.That(sdp.Name, Is.EqualTo("SqlServer.2005"));
                }

                if (context.EndsWith(".2008"))
                {
                    var sdp = conn.DataProvider;
                    Assert.That(sdp.Name, Is.EqualTo("SqlServer.2008"));
                }
            }
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:27,代码来源:DataConnectionTest.cs

示例7: Test

        public void Test(string context)
        {
            SqlServerTools.ResolveSqlTypes("");

            using (var conn = new DataConnection(context))
            {
                var sp       = conn.DataProvider.GetSchemaProvider();
                var dbSchema = sp.GetSchema(conn);

                dbSchema.Tables.ToDictionary(
                    t => t.IsDefaultSchema ? t.TableName : t.SchemaName + "." + t.TableName,
                    t => t.Columns.ToDictionary(c => c.ColumnName));

                var table = dbSchema.Tables.SingleOrDefault(t => t.TableName.ToLower() == "parent");

                Assert.That(table,               Is.Not.Null);
                Assert.That(table.Columns.Count, Is.EqualTo(2));

            //				Assert.That(dbSchema.Tables.Single(t => t.TableName.ToLower() == "doctor").ForeignKeys.Count, Is.EqualTo(1));

                switch (context)
                {
                    case ProviderName.SqlServer2000 :
                    case ProviderName.SqlServer2005 :
                    case ProviderName.SqlServer2008 :
                    case ProviderName.SqlServer2012 :
                        var indexTable = dbSchema.Tables.Single(t => t.TableName == "IndexTable");
                        Assert.That(indexTable.ForeignKeys.Count,                Is.EqualTo(1));
                        Assert.That(indexTable.ForeignKeys[0].ThisColumns.Count, Is.EqualTo(2));
                        break;
                }
            }
        }
开发者ID:pebezo,项目名称:linq2db,代码行数:33,代码来源:SchemaProviderTest.cs

示例8: TestDataTypes

		public void TestDataTypes(string context)
		{
			using (var conn = new DataConnection(context))
			{
				Assert.That(TestType<long?>       (conn, "bigintDataType",   DataType.Int64),     Is.EqualTo(1000000L));
				Assert.That(TestType<long?>       (conn, "int8DataType",     DataType.Int64),     Is.EqualTo(1000001L));
				Assert.That(TestType<int?>        (conn, "intDataType",      DataType.Int32),     Is.EqualTo(7777777));
				Assert.That(TestType<short?>      (conn, "smallintDataType", DataType.Int16),     Is.EqualTo(100));
				Assert.That(TestType<decimal?>    (conn, "decimalDataType",  DataType.Decimal),   Is.EqualTo(9999999m));
				Assert.That(TestType<IfxDecimal?> (conn, "decimalDataType",  DataType.Decimal),   Is.EqualTo(new IfxDecimal(9999999m)));
				Assert.That(TestType<decimal?>    (conn, "moneyDataType",    DataType.Money),     Is.EqualTo(8888888m));
				Assert.That(TestType<float?>      (conn, "realDataType",     DataType.Single),    Is.EqualTo(20.31f));
				Assert.That(TestType<double?>     (conn, "floatDataType",    DataType.Double),    Is.EqualTo(16.2d));

				Assert.That(TestType<bool?>       (conn, "boolDataType",     DataType.Boolean),   Is.EqualTo(true));

				Assert.That(TestType<string>      (conn, "charDataType",     DataType.Char),      Is.EqualTo("1"));
				Assert.That(TestType<string>      (conn, "varcharDataType",  DataType.VarChar),   Is.EqualTo("234"));
				Assert.That(TestType<string>      (conn, "ncharDataType",    DataType.NChar),     Is.EqualTo("55645"));
				Assert.That(TestType<string>      (conn, "nvarcharDataType", DataType.NVarChar),  Is.EqualTo("6687"));
				Assert.That(TestType<string>      (conn, "lvarcharDataType", DataType.NVarChar),  Is.EqualTo("AAAAA"));

				Assert.That(TestType<DateTime?>   (conn, "dateDataType",     DataType.Date),      Is.EqualTo(new DateTime(2012, 12, 12)));
				Assert.That(TestType<DateTime?>   (conn, "datetimeDataType", DataType.DateTime2), Is.EqualTo(new DateTime(2012, 12, 12, 12, 12, 12)));
				Assert.That(TestType<IfxDateTime?>(conn, "datetimeDataType", DataType.DateTime),  Is.EqualTo(new IfxDateTime(new DateTime(2012, 12, 12, 12, 12, 12))));
				Assert.That(TestType<TimeSpan?>   (conn, "intervalDataType", DataType.Time),      Is.EqualTo(new TimeSpan(12, 12, 12)));
				Assert.That(TestType<IfxTimeSpan?>(conn, "intervalDataType", DataType.Time),      Is.EqualTo(new IfxTimeSpan(new TimeSpan(12, 12, 12))));

				Assert.That(TestType<string>      (conn, "textDataType",     DataType.Text,      skipPass:true), Is.EqualTo("BBBBB"));
				Assert.That(TestType<string>      (conn, "textDataType",     DataType.NText,     skipPass:true), Is.EqualTo("BBBBB"));
				Assert.That(TestType<byte[]>      (conn, "byteDataType",     DataType.Binary,    skipPass:true), Is.EqualTo(new byte[] { 1, 2 }));
				Assert.That(TestType<byte[]>      (conn, "byteDataType",     DataType.VarBinary, skipPass:true), Is.EqualTo(new byte[] { 1, 2 }));
			}
		}
开发者ID:donners77,项目名称:linq2db,代码行数:34,代码来源:InformixTest.cs

示例9: Test2

		public void Test2()
		{
			using (var conn = new DataConnection())
			{
				Assert.That(conn.Connection.State,    Is.EqualTo(ConnectionState.Open));
				Assert.That(conn.ConfigurationString, Is.EqualTo(DataConnection.DefaultConfiguration));
			}
		}
开发者ID:ronnyek,项目名称:linq2db,代码行数:8,代码来源:DataConnectionTests.cs

示例10: NorthwindTest

 public void NorthwindTest([IncludeDataContexts("Northwind")] string context)
 {
     using (var conn = new DataConnection(context))
     {
         var sp       = conn.DataProvider.GetSchemaProvider();
         var dbSchema = sp.GetSchema(conn);
     }
 }
开发者ID:henleygao,项目名称:linq2db,代码行数:8,代码来源:SchemaProviderTest.cs

示例11: Test1

 public void Test1([IncludeDataContexts("Northwind")] string context)
 {
     using (var conn = new DataConnection(SqlServerFactory.GetDataProvider(), "Server=.;Database=Northwind;Integrated Security=SSPI"))
     {
         Assert.That(conn.Connection.State,    Is.EqualTo(ConnectionState.Open));
         Assert.That(conn.ConfigurationString, Is.Null);
     }
 }
开发者ID:henleygao,项目名称:linq2db,代码行数:8,代码来源:DataConnectionTest.cs

示例12: Main

		static void Main(string[] args)
		{
			SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

			using (var db = new DataConnection())
			{
				var list = db.GetTable<AllTypes2>().ToList();
			}
		}
开发者ID:donners77,项目名称:linq2db,代码行数:9,代码来源:Program.cs

示例13: TestScalar2

		public void TestScalar2(string context)
		{
			using (var conn = new DataConnection(context))
			{
				var list = conn.Query<int>("SELECT 1").ToList();

				Assert.That(new[] { 1 }, Is.EquivalentTo(list));
			}
		}
开发者ID:donners77,项目名称:linq2db,代码行数:9,代码来源:DataExtensionsTest.cs

示例14: TestScalar2

		public void TestScalar2([IncludeDataContexts(ProviderName.SqlServer)] string context)
		{
			using (var conn = new DataConnection(context))
			{
				var list = conn.Query<int>("SELECT 1").ToList();

				Assert.That(new[] { 1 }, Is.EquivalentTo(list));
			}
		}
开发者ID:henleygao,项目名称:linq2db,代码行数:9,代码来源:DataExtensionsTest.cs

示例15: ReplaceDataObjectsInBulkActorFactory

 public ReplaceDataObjectsInBulkActorFactory(
     IReadOnlyCollection<Type> dataObjectTypes,
     DataConnection sourceDataConnection,
     DataConnection targetDataConnection)
 {
     _dataObjectTypes = dataObjectTypes;
     _sourceDataConnection = sourceDataConnection;
     _targetDataConnection = targetDataConnection;
 }
开发者ID:2gis,项目名称:nuclear-river,代码行数:9,代码来源:ReplaceDataObjectsInBulkActorFactory.cs


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