本文整理汇总了C#中DataContext.First方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.First方法的具体用法?C# DataContext.First怎么用?C# DataContext.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContext
的用法示例。
在下文中一共展示了DataContext.First方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: S_DataObject_Should_CRUD_An_Item_With_Shared_Transactional_Data_Context
public void S_DataObject_Should_CRUD_An_Item_With_Shared_Transactional_Data_Context()
{
using (var context = new DataContext())
{
var dodge = new Manufacturer { Name = "Dodge", BuildYear = 1900 };
manufacturerDataObject.Insert(dodge, context);
dodge.BuildYear = 1915;
manufacturerDataObject.Update(dodge, context);
var updatedDodge = context.First<Manufacturer>("SELECT TOP 1 * FROM Le_Manufacturer WHERE Name = 'Dodge'");
var m4s = new Car { Name = "M4S", ModelYear = 1984, Category = CarCategory.Prototype, ManufacturerId = dodge.TheId };
carDataObject.Insert(m4s, context);
var createdM4s = carDataObject.Select.With(context).First("WHERE Name = 'M4S'");
carDataObject.Delete(m4s, context);
var deletedM4s = carDataObject.Select.With(context).First("WHERE Name = 'M4S'");
updatedDodge.BuildYear.Should().Be(1915);
createdM4s.Should().NotBeNull();
deletedM4s.Should().BeNull();
context.Commit();
}
var createdDodgeOutsiteContext = manufacturerDataObject.Select.First("WHERE Name = 'Dodge'");
createdDodgeOutsiteContext.Should().NotBeNull();
}
示例3: M_DataObject_Should_Insert_Item_From_Database_And_Set_Primery_Key
public void M_DataObject_Should_Insert_Item_From_Database_And_Set_Primery_Key()
{
var car = new Car { Name = "Aventador", ModelYear = 2011, Category = CarCategory.Sport };
carDataObject.Insert(car);
car.Id.Should().BeGreaterThan(0);
using (var context = new DataContext())
{
var query = "SELECT TOP 1 * FROM Car WHERE Name = 'Aventador'";
var createdManufacturer = context.First<Car>(query);
createdManufacturer.Should().NotBeNull();
}
}
示例4: J_DataContext_Reader_First_Should_Return_A_Null_Object_When_Query_Do_Not_Found_Items
public void J_DataContext_Reader_First_Should_Return_A_Null_Object_When_Query_Do_Not_Found_Items()
{
using (var context = new DataContext())
{
var car = context.First<Car>("SELECT * FROM Car WHERE Name = 'Fusca'");
car.Should().BeNull();
}
}
示例5: H_DataContext_Reader_Should_Translate_DBNull_To_Null_Value
public void H_DataContext_Reader_Should_Translate_DBNull_To_Null_Value()
{
using (var context = new DataContext())
{
context.Execute("UPDATE Car SET Name = NULL WHERE Name = 'Esprit Turbo'");
var car = context.First<Car>("SELECT * FROM Car WHERE Name IS NULL");
car.Name.Should().BeNull();
}
}
示例6: F_DataContext_Should_Read_Data_With_One_Field_And_Insert_A_Data_With_Some_Parameters_Types
public void F_DataContext_Should_Read_Data_With_One_Field_And_Insert_A_Data_With_Some_Parameters_Types()
{
using (var context = new DataContext())
{
var selectParameters = new { Name = "Lotus" };
var manufacturer = context.First<Manufacturer>("SELECT TheId FROM Le_Manufacturer WHERE Name = @Name", selectParameters);
var insertParameters = new Car
{
Name = "Esprit Turbo",
ModelYear = 1981,
Mileage = 318.19850801,
ManufacturerId = manufacturer.TheId,
Category = CarCategory.Sport
};
context.Execute("INSERT INTO Car VALUES (@Name, @ModelYear, @CreatedAt, @Chassis, @Mileage, @Category, @ManufacturerId)", insertParameters);
var car = context.First<Car>("SELECT TOP 1 * FROM Car");
context.Commit();
car.Id.Should().BeGreaterThan(0);
car.Name.Should().Be("Esprit Turbo");
car.ModelYear.Should().Be(1981);
car.Mileage.Should().Be(318.19850801);
car.ManufacturerId.Should().Be(manufacturer.TheId);
car.CreatedAt.Date.Should().Be(DateTime.Today.Date);
car.Category.Should().Be(CarCategory.Sport);
}
}
示例7: E_DataContext_Transitional_Should_Execute_A_SQL_And_Share_Transaction_With_A_Data_Reader
public void E_DataContext_Transitional_Should_Execute_A_SQL_And_Share_Transaction_With_A_Data_Reader()
{
using (var context = new DataContext())
{
var insertParameters = new { Name = "BMW", Year = 1916 };
context.Execute("INSERT INTO Le_Manufacturer VALUES (@Name, @Year)", insertParameters);
var selectParameters = new { Name = "BMW" };
var manufacturer = context.First<Manufacturer>("SELECT * FROM Le_Manufacturer WHERE Name = @Name", selectParameters);
manufacturer.Should().NotBeNull();
}
using (var context = new DataContext())
{
var selectParameters = new { Name = "BMW" };
var manufacturer = context.First<Manufacturer>("SELECT * FROM Le_Manufacturer WHERE Name = @Name", selectParameters);
manufacturer.Should().BeNull();
}
}