Page 1 of 1

NotImplementedException while using SubmitChanges ( LINQ )

Posted: Fri 21 Aug 2009 17:29
by drichter
imagine i got a table ( testtable) with 2 columns:

- id ( PK )
- value

and a function call like this:

public void main()
{
testtable t = new testtable();
t.id = 10;
t.value = "test";
Updatetesttable(t);
}

public void Updatetesttable(testtable t)
{
DataContext db = new DataContext();
db.testtables.SubmitChanges(t);
}

An entry with id=10 actually exists in the db, but:

The "bold" part of the source throws a "NotImplementedException"... How am i supposed to update a table when i DON'T have access to the DataContext where i made the select with?!?!

Thanks ( this is very urgent )!

Posted: Mon 24 Aug 2009 12:08
by drichter
hello? administration? :)

Posted: Tue 25 Aug 2009 09:25
by Shalex
The update can be done as the following:

Code: Select all

    static void Main(string[] args) {

      Testtable oldT = new Testtable();
      oldT.Id = 10;
      oldT.Value = "test";
      
      Testtable newT = new Testtable();
      newT.Id = 10;
      newT.Value = "new test";

      Updatetesttable(newT, oldT);
    }

    public static void Updatetesttable(Testtable newT, Testtable oldT) {
      Postgresdatacontext db = new Postgresdatacontext();
      db.Testtables.Attach(newT, oldT);
      db.SubmitChanges();
    }
An alternative way:

Code: Select all

        DataContext db = new DataContext();
        var row = db.Testtables.Single(c => c.Id == 10);
        row.Value = "new test";
        db.SubmitChanges();