In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the methods of using LINQ to SQL sentences". In daily operation, I believe that many people have doubts about the use of LINQ to SQL sentences. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the use of LINQ to SQL sentences?" Next, please follow the editor to study!
Simple form of LINQ to SQL statement
Description: new an object, add it to the corresponding collection using the InsertOnSubmit method, and submit it to the database using SubmitChanges ().
NorthwindDataContext db = new NorthwindDataContext (); var newnewCustomer = newCustomer {CustomerID = "MCSFT", CompanyName = "Microsoft", ContactName = "John Doe", ContactTitle = "Sales Manager", Address = "1 Microsoft Way", City = "Redmond", Region = "WA", PostalCode = "98052", Country = "USA", Phone = "(425) 555-1234", Fax = null}
Statement description: use the InsertOnSubmit method to add a new customer to the Customers table object. Call SubmitChanges to save this new Customer to the database.
LINQ to SQL statement one-to-many relationship
Note: Category and Product have an one-to-many relationship. When submitting data from Category (one side), LINQ to SQL will automatically submit data from Product (multiple terminals) together.
Var newnewCategory = newCategory {CategoryName = "Widgets", Description = "Widgets are the." }; var newnewProduct = newProduct {ProductName = "Blue Widget", UnitPrice = 34.56m, Category = newCategory}
Statement description: use the InsertOnSubmit method to add a new category to the Categories table and add a new Product object to the Products table that has a foreign key relationship with this new Category. Call SubmitChanges to save these new objects and their relationships to the database.
Many-to-many relationship of LINQ to SQL statement
Description: in a many-to-many relationship, we need to submit in turn.
Var newnewEmployee = newEmployee {FirstName = "Kira", LastName = "Smith"}; var newnewTerritory = newTerritory {TerritoryID = "12345", TerritoryDescription = "Anytown", Region = db.Regions.First ()}; var newnewEmployeeTerritory = newEmployeeTerritory {Employee = newEmployee, Territory = newTerritory}; at this point, the study of "what is the use of LINQ to SQL sentences" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.