Install Nuget Package from Visual Studio ( Entity Framework)
Add EntityFramework.dll
and EntityFramewok.SqlServer.dll into references.
1) If you want to select rows from Table :
using (dbEntities db = new dbEntities())
{
var result = db.Customers.Select(x => x).OrderBy(x => x.Customer_ID).ToList();
var result = db.QTMS_JohnToGo_Equipment.Where(x => x.Is_Deleted == false).Select(x => x).OrderBy(x => x.Equipment_ID).ToList();
var lst = db.QTMS_VipToGo_Equipment.Where(x => x.Is_Deleted == false && x.Equipment_ID == id).Select(x => x.Equipment_Description).ToList();
if (lst != null && lst.Count() > 0)
return JsonConvert.SerializeObject(lst);
}
//jquery code
alert("My age is : " + Bresponse[0].Customer_Age);
//Code Behind for Adding / Update records in Entity Framework.
[WebMethod]
public static string GetCustomerData(string entity)
{
using (ViftechEntities db = new ViftechEntities())
{
JavaScriptSerializer js = new JavaScriptSerializer();
Customer defaultdata = (Customer)js.Deserialize(entity, typeof(Customer));
Customer obj;
//update
if (defaultdata.Customer_ID > 0)
{
// obj = new Customer();
obj = db.Customers.Where(x => x.Customer_ID == defaultdata.Customer_ID).FirstOrDefault();
if (obj != null)
{
obj.Customer_Age = 12;
obj.Customer_Name = "Naya Naam";
db.SaveChanges();
}
}
//add new
else
{
obj = new Customer();
obj.Customer_Name = "Salman";
obj.Customer_Age = 29;
db.Customers.Add(obj);
db.SaveChanges();
}
var result = db.Customers.Select(x => x).OrderBy(x => x.Customer_ID).ToList();
return JsonConvert.SerializeObject(result);
}
}