להלן דוגמאות לקריאה וכתיבה לבסיס הנתונים.
להזכירכם: בראש כל עמוד חייבת להיות השורה:
dbEntities db = new dbEntities();
//function that retrive data from fb
public void printUsers()
{
Response.Write("<table>");
var tmp = (from s in db.user select s).ToList();
foreach(user x in tmp){
Response.Write("<tr>");
Response.Write("<td>");
Response.Write(x.firstname);
Response.Write("</td>");
Response.Write("<td>");
Response.Write(x.lastname);
Response.Write("</td>");
Response.Write("</tr>");
}
Response.Write("</table>");
}
//insert data to db
public void regUser(String firstname, String lastname, int age, String vehicle)
{
//create new user entity
user u1 = new user();
u1.firstname = firstname;
u1.lastname = lastname;
u1.age = age;
u1.vehicle = vehicle;
//insert user into DB
db.user.AddObject(u1);
//save db
db.SaveChanges();
}