0

I have created an ADO.NET entity data model, and using linq to update/edit my oracle database.

using (Entities ent = new Entities())
{
    RUSHPRIORITYRATE rp = new RUSHPRIORITYRATE();
    rp.RATE = rate;
    var query = from j in ent.RUSHPRIORITYRATEs
                        select j;
    List<RUSHPRIORITYRATE> list = query.ToList();
    if (list.Count == 0)
    {
        ent.AddToRUSHPRIORITYRATEs(rp);
        ent.SaveChanges();
    }
    else
    {
        foreach (RUSHPRIORITYRATE r in query)
        {
            r.RATE = rp.RATE;
        }
        ent.SaveChanges();
    }


}

I have a method that either adds or updates a Table that will always have one record. The record's value is then only update once there is one record in place. Adding to the table is no problem, but I've looked up how to update recores through MSDN, and "ent" does not seem to have the "submitchanges" method that the solution requires. Running this, I get the error: "The property 'RATE' is part of the object's key information and cannot be modified."

Erika
  • 289
  • 1
  • 5
  • 20
  • `SubmitChanges` is linq-to-sql. The exception message is pretty clear: you cannot update an object's key. Why do you want to update `RATE` and why is it part of the key? Can you show the relevant part of your model. It will help you to get more help. – Gert Arnold Aug 20 '12 at 22:01
  • Well there is only one record with one attribute, that being the rate. Understanding what the exception says is not my problem, I just don't understand why I could do this with other tables and not this specific one. – Erika Aug 20 '12 at 22:32
  • I bet the other tables have more attributes and you don't update their key values. – Gert Arnold Aug 20 '12 at 22:36

0 Answers0