LINQ to Entities allows you to update your database.

c# entity-framework linq-to-entities

Question

I've been doing some research on how to update an existing record using LINQ, but I'm not having any luck. This is the method I've created - intellisense does not like the db.SubmitChanges().

public void updateRestaurant(int RestID, int HoursID, string Web, string Desc)
{
    RestaurantsEntities db = new RestaurantsEntities();
    RESTAURANT restDetails = (from RESTAURANT in db.RESTAURANTs
                                    where RESTAURANT.REST_ID == RestID
                                    select RESTAURANT).Single();
    restDetails.HOURS_ID = HoursID;
    restDetails.REST_WEBSITE = Web;
    restDetails.REST_DESC = Desc;

    db.SubmitChanges();
}
1
2
5/7/2012 5:28:34 AM

Popular Answer

Try using db.SaveChanges();

    public void updateRestaurant(int RestID, int HoursID, string Web, string Desc)
    {
        RestaurantsEntities db = new RestaurantsEntities();
        RESTAURANT restDetails = (from RESTAURANT in db.RESTAURANTs
                                        where RESTAURANT.REST_ID == RestID
                                        select RESTAURANT).Single();
        restDetails.HOURS_ID = HoursID;
        restDetails.REST_WEBSITE = Web;
        restDetails.REST_DESC = Desc;
        db.SaveChanges();
    }
4
5/6/2012 11:50:28 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow