2008/04/01

LINQ基本操作


Insert

Customer
newCust = new Customer();
newCust.CompanyName = "AdventureWorks Cafe";
newCust.CustomerID = "ADVCA";

db.Customers.InsertOnSubmit(newCust);







Update
var existingCust =
(from c in db.Customers
where c.CustomerID == "ALFKI"
select c)
.First();

existingCust.ContactName = "New Contact";







Delete
Order ord0 = existingCust.Orders[0];
OrderDetail detail0 = ord0.OrderDetails[0];
db.OrderDetails.DeleteOnSubmit(detail0);






Submit Changes Item
db.SubmitChanges();

0 pushs: