本文整理汇总了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);
}
}
示例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();
}
示例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());
}