Hi there,
can anyone help? I have an issue with linq2sql and trying to Attach (update) an entity class through a datacontext, it complains its not the original context, this is true (see code below) ... I thought it was best practices to open the datacontext and close it when not needed?
I basically have my app calling a service layer which in turn calls a repository where the db context is.... You can see here i have 2 data contexts, well a datacontext is defined in each method...
Basically what happens is my app "Gets" a reservation ... then the app updates the entity class "Reservation" and then resends it to "Updates" a Reservation.. Can anyone help.. I am completely stuck
here is basicallly my code
    public bool UpdateReservation(Reservation reservation)
    {
        bool success = false;
        try
        {
            ResDataContext db = new ResDataContext ();
            db.Reservations.Attach(reservation);
            db.SubmitChanges();
            success = true;
        }
        catch (Exception ex)
        {
            Console.WriteLine("");
        }
        return success;
    }
    public Reservation GetReservation(string reservationNumber)
    {
        ResDataContext db = new ResDataContext ();
        return db.Reservations.Where(r => r.ReservationNumber == reservationNumber).SingleOrDefault(); 
    }