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


C# DataContext.First方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:20,代码来源:SqlTest.cs

示例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();
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:28,代码来源:SqlTest.cs

示例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();
            }
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:15,代码来源:SqlTest.cs

示例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();
            }
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:9,代码来源:SqlTest.cs

示例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();
            }
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:10,代码来源:SqlTest.cs

示例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);
            }
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:29,代码来源:SqlTest.cs

示例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();
            }
        }
开发者ID:bernardobrezende,项目名称:Thunderstruck,代码行数:20,代码来源:SqlTest.cs


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