c# - entity saveChanges not updating database -
i following tutorial using entity framework in c# , having number of issues.
my first issue not access .load() or addobject() methods through entity. after searching found far has seemed help:
.net framework 4.5 addobject() not appear
after continuing on tutorial having issue when trying save new record database.
using (northwndentities ctx = new northwndentities()) { var customers = c in ctx.customers.include("orders") c.city == "london" select c; //adds customer customer newcustomer = new customer { customerid = "joen", city = "london", contactname = "joe n", companyname = "acme" }; ctx.customers.addobject(newcustomer); ctx.savechanges(); foreach (customer customer in customers) { //customer.orders.load(); console.writeline("customer {0} has {1} orders {2}", customer.contactname, customer.orders.count(), customer.phone); }
when code runs displays newly added customer database not updated.
i have tried suggested solutions on entity framework not save object don't have addto method in entity.
using create
on dbcontext more appropriate , may resolve issue:
customer newcustomer = ctx.customers.create(); newcustomer.customerid = "joen"; ..etc, etc ctx.customers.add(newcustomer); ctx.savechanges();
Comments
Post a Comment