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


C# DataContext.GetValue方法代码示例

本文整理汇总了C#中DataContext.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.GetValue方法的具体用法?C# DataContext.GetValue怎么用?C# DataContext.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataContext的用法示例。


在下文中一共展示了DataContext.GetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: using

        public void B_DataContext_Transitional_Should_Execute_A_Insert_SQL_Command_With_Array_Parameters_And_Read_Created_Data_In_Same_And_Count_Data_In_Another_Context()
        {
            using (var context = new DataContext())
            {
                context.Execute("INSERT INTO Le_Manufacturer VALUES (@0, @1)", "McLaren", 1963);
                var manufacturer = context.First<Manufacturer>("SELECT TOP 1 * FROM Le_Manufacturer WHERE Name = @0", "McLaren");
                context.Commit();

                manufacturer.TheId.Should().BeGreaterThan(0);
                manufacturer.Name.Should().Be("McLaren");
                manufacturer.BuildYear.Should().Be(1963);
            }

            using (var context = new DataContext())
            {
                var manufacturerCount = context.GetValue<int>("SELECT COUNT(TheId) FROM Le_Manufacturer");

                manufacturerCount.Should().Be(2);
            }
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:20,代码来源:SqlTest.cs

示例2: DataContext_Should_Get_A_Value_From_Database

        public void DataContext_Should_Get_A_Value_From_Database()
        {
            using (var context = new DataContext())
            {
                var value = context.GetValue("SELECT COUNT(Id) FROM Airplane");
            }

            connectionMock.Verify(c => c.Open(), Times.Once());
            connectionMock.Verify(c => c.Close(), Times.Once());
            connectionMock.Verify(c => c.BeginTransaction(), Times.Never());
            commandMock.Verify(c => c.ExecuteScalar(), Times.Once());
            commandMock.VerifySet(c => c.CommandText = "SELECT COUNT(Id) FROM Airplane");
            providerMock.Object.DbTransaction.Should().BeNull();
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:14,代码来源:DataContextTest.cs

示例3: DataContext_Should_Get_A_Typed_Value_From_Database

        public void DataContext_Should_Get_A_Typed_Value_From_Database()
        {
            commandMock.Setup(c => c.ExecuteScalar()).Returns(1);

            using (var context = new DataContext())
            {
                var value = context.GetValue<int>("SELECT COUNT(Id) FROM Airplane");
            }

            commandMock.Verify(c => c.ExecuteScalar(), Times.Once());
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:11,代码来源:DataContextTest.cs


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