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


C# NorthwindEntities.SaveChanges方法代码示例

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


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

示例1: InsertCustomer

    public static void InsertCustomer(string customerId, string companyName, string contactName, string contactTitle,
        string adress, string city, string region, string postalCode, string country, string phone, string fax)
    {
        if (customerId.Length == 0 || customerId.Length>5)
        {
            throw new ArgumentException("The lenght of CustomerId must be between 0 and 5 characters!");
        }

        using (NorthwindEntities nwDb = new NorthwindEntities())
        {
            Customer cusomer = new Customer
            {
                CustomerID = customerId,
                CompanyName = companyName,
                ContactName = contactName,
                ContactTitle = contactTitle,
                Address = adress,
                City = city,
                Region = region,
                PostalCode = postalCode,
                Country = country,
                Phone = phone,
                Fax = fax
            };
            nwDb.Customers.Add(cusomer);
            nwDb.SaveChanges();
        }
    }
开发者ID:nim-ohtar,项目名称:TelerikAcademy-2,代码行数:28,代码来源:CustomerControler.cs

示例2: DeleteCustomer

 public static void DeleteCustomer(NorthwindEntities dbNorthwnd)
 {
     var customer = dbNorthwnd.Customers.Where(z => z.CustomerID == "AAAA1").First();
     dbNorthwnd.Customers.Remove(customer);
     var affectedRows = dbNorthwnd.SaveChanges();
     Console.WriteLine("({0} row(s) affected)", affectedRows);
 }
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:7,代码来源:ADO.cs

示例3: InsertCustomer

    public static void InsertCustomer(string customerID, string companyName, string contactName = null, string contactTitle = null,
                                      string address = null, string city = null, string region = null, string postalCode = null,
                                      string country = null, string phone = null, string fax = null)
    {
        using (NorthwindEntities northwindDBContext = new NorthwindEntities())
        {
            Customer customer = new Customer
            {
                CustomerID = customerID,
                CompanyName = companyName,
                ContactName = contactName,
                ContactTitle = contactTitle,
                Address = address,
                City = city,
                Region = region,
                PostalCode = postalCode,
                Country = country,
                Phone = phone,
                Fax = fax
            };

            northwindDBContext.Customers.Add(customer);

            northwindDBContext.SaveChanges();
            Console.WriteLine("Row is inserted.");
        }
    }
开发者ID:skirov,项目名称:TA-Databases,代码行数:27,代码来源:Northwind.Lib.cs

示例4: Main

    // First way
    static void Main()
    {
        using (NorthwindEntities firstDB = new NorthwindEntities())
        {
            using (NorthwindEntities secondDB = new NorthwindEntities())
            {
                var firstCustomer =
                    (from c in firstDB.Customers
                     where c.CustomerID == "PARIS"
                     select c).First();

                var secondCustomer =
                    (from c in secondDB.Customers
                     where c.CustomerID == "PARIS"
                     select c).First();

                firstCustomer.CompanyName = "First Change with LINQ";
                secondCustomer.ContactName = "Second Change with LINQ";

                firstDB.SaveChanges();
                secondDB.SaveChanges();
                Console.WriteLine("Changes are made successfully!");

                //SecondWayForChangeRecords();
            }
        }
    }
开发者ID:Nikolay-D,项目名称:TelerikSchoolAcademy,代码行数:28,代码来源:SameChanges.cs

示例5: ModifyProductName

	static void ModifyProductName(int productId, string newName)
	{
		NorthwindEntities northwindEntities = new NorthwindEntities();
		Product product = GetProductById(northwindEntities, productId);
		product.ProductName = newName;
		northwindEntities.SaveChanges();
	}
开发者ID:syssboxx,项目名称:SchoolAcademy,代码行数:7,代码来源:UpdatingDeletingInsertingData.cs

示例6: Main

        static void Main(string[] args)
        {
            Customer newCustmer = new Customer();
            newCustmer.CustomerID = "KULO";
            newCustmer.CompanyName = "Mala";
            newCustmer.ContactName = "Misoto Kulano";
            newCustmer.ContactTitle = "Owner";
            newCustmer.Address = "Amela str 23";
            newCustmer.City = "Pelon";
            newCustmer.PostalCode = "1231";
            newCustmer.Country = "France";
            newCustmer.Phone = "3443-4323-432";
            newCustmer.Fax = "3245-243";

            using (var otherDataBase = new NorthwindEntities())
            {

                using (var dataBase = new NorthwindEntities())
                {
                    otherDataBase.Customers.Add(newCustmer);
                    otherDataBase.SaveChanges();
                    //Customer customer = dataBase.Customers.First(x => x.CustomerID == "KULO");
                    dataBase.Customers.Attach(newCustmer);
                    dataBase.Customers.Remove(newCustmer);
                    dataBase.SaveChanges();
                }
            }
        }
开发者ID:Gerya,项目名称:TelerikAcademy,代码行数:28,代码来源:SameChanges.cs

示例7: InsertOrder

    static void InsertOrder(
        string shipName, string shipAddress,
        string shipCity, string shipRegionm,
        string shipPostalCode,string shipCountry,
        string customerID = null, int? employeeID = null,
        DateTime? orderDate = null, DateTime? requiredDate = null,
        DateTime? shippedDate = null, int? shipVia = null,
        decimal? freight = null)
    {
        using (NorthwindEntities context = new NorthwindEntities())
        {
            Order newOrder = new Order
            {
                ShipAddress = shipAddress,
                ShipCity = shipCity,
                ShipCountry = shipCountry,
                ShipName = shipName,
                ShippedDate = shippedDate,
                ShipPostalCode = shipPostalCode,
                ShipRegion = shipRegionm,
                ShipVia = shipVia,
                EmployeeID = employeeID,
                OrderDate = orderDate,
                RequiredDate = requiredDate,
                Freight = freight,
                CustomerID = customerID
            };

            context.Orders.Add(newOrder);

            context.SaveChanges();

            Console.WriteLine("Row is inserted.");
        }
    }
开发者ID:C3co0o0o,项目名称:Databases,代码行数:35,代码来源:09.AddNewOrder.cs

示例8: DeleteProduct

	static void DeleteProduct(int productId)
    {
		NorthwindEntities northwindEntities = new NorthwindEntities();
		Product product = GetProductById(northwindEntities, productId);
        northwindEntities.Products.Remove(product);
		northwindEntities.SaveChanges();
    }
开发者ID:syssboxx,项目名称:SchoolAcademy,代码行数:7,代码来源:UpdatingDeletingInsertingData.cs

示例9: PlaceNewOrder

    static void PlaceNewOrder(string customerId,int employeeId,Order_Detail[] details)
    {
        using (NorthwindEntities nwDb = new NorthwindEntities())
        {
            using (TransactionScope scope = new TransactionScope())
            {

                Order order = new Order
                {
                    CustomerID = customerId,
                    EmployeeID = employeeId,
                    ShipVia = 1,
                    ShipName = "UnknownShip",
                    ShipAddress = "UnknownAddress",
                    ShipCity = "Unknown",
                    ShipRegion = "Unknown",
                    ShipPostalCode = "121311",
                    ShipCountry = "Unknown",
                    Order_Details = details

                };

                nwDb.Orders.Add(order);
                nwDb.SaveChanges();

                scope.Complete();
            }
        }
    }
开发者ID:nim-ohtar,项目名称:TelerikAcademy-2,代码行数:29,代码来源:Program.cs

示例10: AddCustomer

        public static void AddCustomer(NorthwindEntities dbNorthwnd, string name)
        {
            var customer = new Customer()
            {
                CustomerID = "AAAA" + name,
                CompanyName = "YYYY" + name,
                ContactName = "Pesho Peshev",
                ContactTitle = "Shef",
                Address = "aaaaaaaaaa",
                City = "Sofia",
                PostalCode = "1330",
                Country = "Bulgaria",
                Phone = "0000000",
                Fax = "0000000"
            };
            dbNorthwnd.Customers.Add(customer);
            try
            {
                dbNorthwnd.SaveChanges();
            }
            catch (Exception ex)
            {

            }
        }
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:25,代码来源:ADO.cs

示例11: Main

        static void Main(string[] args)
        {
            NorthwindEntities firstContext = new NorthwindEntities();
            NorthwindEntities secondContext = new NorthwindEntities();

            firstContext.Customers.Add(new Customer() { CustomerID = "ALABA", CompanyName = "Some company" });
            firstContext.SaveChanges();
           
            //the second command will be the final because there is no conflict resolution
            firstContext.Customers.Find("ALABA").ContactName = "Bacho Kiro";
            secondContext.Customers.Find("ALABA").ContactName = "Bai Stavri";

            firstContext.SaveChanges();
            secondContext.SaveChanges();
            

        }
开发者ID:Cecosam,项目名称:Csharp-Projects,代码行数:17,代码来源:Program.cs

示例12: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        //NorthwindEntities objectContext = new NorthwindEntities();
        ////inner join
        //var result = from cat in objectContext.Categories
        //             join prod in objectContext.Products
        //             on cat.CategoryID equals prod.CategoryID
        //             group cat by cat.CategoryID into groupedCategories
        //             select new { CategoryID = groupedCategories.Key };
        
        //GridView1.DataSource = result;
        //GridView1.DataBind();

        ////outer join
        //var result1 = from cat in objectContext.Categories
        //             join prod in objectContext.Products
        //             on cat.CategoryID equals prod.CategoryID
        //             into groupedCategories
        //             select new { CategoryID = cat.CategoryID };
        //GridView2.DataSource = result1;
        //GridView2.DataBind();

        //var result2 = objectContext.Categories.Where((item) => (item.CategoryID == 287389)).Select((item) => (item)).First();
        //result2.CategoryName = "mumbai";        
        //objectContext.Categories.AddObject( new Category() { CategoryID = 876221, CategoryName = "India" });
        //objectContext.SaveChanges();

        //var result3 = objectContext.Categories.First<Category>((cat) => (cat.CategoryID == 65985));
        //result3.CategoryName = "london";
        //objectContext.SaveChanges();

        //var result4 = objectContext.Categories.First<Category>((cat) => (cat.CategoryID == 876221));
        //objectContext.DeleteObject(result4);
        //objectContext.SaveChanges();

        //var result5 = objectContext.Categories.Where((cat) => (cat.CategoryID == 287389)).First<Category>();
        //Product prod1 = new Product() { CategoryID = result5.CategoryID, ProductID = 72561, ProductName = "film", UnitPrice = 56, UnitsInStock = 132, Category = result5 };
        //objectContext.Products.AddObject(prod1);
        //objectContext.SaveChanges();

        NorthwindEntities end1 = new NorthwindEntities();
        var result6 = from item in end1.Products
                      select item;
        GridView1.DataSource = result6;
        GridView1.DataBind();

        var result7 = from cat in end1.Categories
                      join prod in end1.Products
                      on cat.CategoryID equals prod.CategoryID
                      select new { CategoryName = cat.CategoryName, ProductName = prod.ProductName };

        GridView1.DataSource = result7;
        GridView1.DataBind();

        var result8 = end1.Categories.Where<Category>((cat) => (cat.CategoryID == 287389)).First<Category>();
        result8.CategoryName = "paris";
        end1.SaveChanges();
    }
开发者ID:naynishchaughule,项目名称:ASP.NET,代码行数:58,代码来源:Home.aspx.cs

示例13: Update

 public static void Update(string id, string companyName)
 {
     var northwindEntities = new NorthwindEntities();
     Customer customer = northwindEntities.Customers.FirstOrDefault(
        c => c.CustomerID == id);
     customer.CompanyName = companyName;
     northwindEntities.SaveChanges();
     Console.WriteLine("Customer with id: {0} successfully eddited", id);
 }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:9,代码来源:DBFunction.cs

示例14: Delete

 public static void Delete(string id)
 {
     var northwindEntities = new NorthwindEntities();
     Customer customer = northwindEntities.Customers.FirstOrDefault(
        c => c.CustomerID == id);
     northwindEntities.Customers.Remove(customer);
     northwindEntities.SaveChanges();
     Console.WriteLine("Customer with ID: {0} successfully removed! ", id);
 }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:9,代码来源:DBFunction.cs

示例15: UpdateProduct

 static void UpdateProduct(Product product, string newName)
 {
     using (NorthwindEntities northwindEntities = new NorthwindEntities())
     {
         northwindEntities.Products.Attach(product); // This line is required!
         product.ProductName = newName;
         northwindEntities.SaveChanges();
     }
 }
开发者ID:Dyno1990,项目名称:TelerikAcademy-1,代码行数:9,代码来源:AttachDetachEntities.cs


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