First, create a list named myproducts on our test website, and define that the three customer columns are of the string type.
Of course, you do not need to insert any records.
Next we will add, delete, and modify this list as an object.
1. Add operation
VaR Dc = New Northwindentitydatacontext (spcontext. Current. Web. url );
Entitylist <myproductsitem> mycustproducts;
Mycustproducts = Dc. getlist <myproductsitem> ( " Myproducts " );
String Productnamestr = " Newproductname " ;
Myproductsitem newproduct = New Myproductsitem ();
Newproduct. Title = " Atestprd " + Datetime. Now. tow.timestring (). Trim ();
Newproduct. productname = productnamestr;
Newproduct. productprice = " 15 " ;
DC. myproducts. insertonsubmit (newproduct );
DC. submitchanges ();
2. Modification Operation
VaR Dc = New Northwindentitydatacontext (spcontext. Current. Web. url );
Entitylist <myproductsitem> mycustproducts;
String Productnamestr = " Modifiedproductname " ;
Mycustproducts = Dc. getlist <myproductsitem> ( " Myproducts " );
VaR Updateitem = ( From P In Mycustproducts
Where P. productname = productnamestr
Select P). First ();
Updateitem. Title = " Updated " + Productnamestr;
//Submit the changes
DC. submitchanges ();
3. Delete
VaR Dc = New Northwindentitydatacontext (spcontext. Current. Web. url );
Entitylist <myproductsitem> mycustproducts;
Mycustproducts = Dc. getlist <myproductsitem> ( " Myproducts " );
String Productnamestr = This . Txtbxproductname. Text. tostring ();
// Querying the list item that has to be deleted
VaR Delitem = ( From P In Mycustproducts
Where P. productname = productnamestr
Select P). First ();
//Deleting the list item
Mycustproducts. deleteonsubmit (delitem );
//Submit the changes
DC. submitchanges ();