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

C# Data.DataConnection类代码示例

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

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



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


示例16: EnumExecuteScalarTest

		public void EnumExecuteScalarTest()
		{
			using (var dbm = new DataConnection())
			{
				var gender = dbm.Execute<Gender>("select 'M'");

				Assert.That(gender, Is.EqualTo(Gender.Male));
			}
		}
开发者ID:ronnyek,项目名称:linq2db,代码行数:9,代码来源:DataConnectionTests.cs


示例17: TestObject1

		public void TestObject1(string context)
		{
			using (var conn = new DataConnection(context))
			{
				var list = conn.Query<QueryObject>("SELECT 1 as Column1, CURRENT_TIMESTAMP as Column2").ToList();

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


示例18: TestScalar3

		public void TestScalar3(string context)
		{
			using (var conn = new DataConnection(context))
			{
				var list = conn.Query<DateTimeOffset>("SELECT CURRENT_TIMESTAMP").ToList();

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


示例19: DatabaseUpgrader

        public DatabaseUpgrader(DataConnection conn)
        {
            connection = conn;

            upgrades = new Dictionary<string, Func<string>>
            {
                ["1.1"] = UpgradeFrom1_1,
                ["1.2"] = UpgradeFrom1_2
            };
        }
开发者ID:Baggykiin,项目名称:BaggyBot-2,代码行数:10,代码来源:DatabaseUpgrader.cs


示例20: Test

		public void Test(string context)
		{
			using (var db = new DataConnection(context))
			{
				var p1 = PersonSelectByKey(db, 1).First();
				var p2 = db.Query<Person>("SELECT * FROM Person WHERE PersonID = @id", new { id = 1 }).First();

				Assert.AreEqual(p1, p2);
			}
		}
开发者ID:donners77,项目名称:linq2db,代码行数:10,代码来源:ProcedureTest.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# LinqToSQLModel.MainDBDataContext类代码示例发布时间:2022-05-26
下一篇:
C# Datatypes.TalkException类代码示例发布时间: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