Page 1 of 1

EntryEntities.Attach

Posted: Thu 24 Sep 2009 11:45
by Falke
Is it possible to Attach objects to contexts?

context.EntryEntities.Attach(entity, true);

??

Posted: Thu 24 Sep 2009 13:35
by AndreyR
Yes, this method is supported.

Posted: Wed 30 Sep 2009 07:17
by Falke
how is the correct call? to detach and attach it? do you have a small example?

Posted: Thu 01 Oct 2009 14:43
by AndreyR
Here is a simple code example:

Code: Select all

   private void MainMethod () {
      Customer c = getFirst();
      c.Name = "Test";
      DataContext1.DataContext1 context = new DataContext1.DataContext1();
      context.Customers.Attach(c, true);
      context.SubmitChanges();
    }
    private Customer getFirst () {
      using (DataContext1.DataContext1 context = new DataContext1.DataContext1()) 
      {
        Customer c = db.Customers.First();
        return c;
      }
    }
Please note that the Customer object has a version field with a trigger on insert and update actions,
setting the version value to current timestamp.

Posted: Thu 01 Oct 2009 20:33
by Falke
doesn't work in my case:

i got following error:

An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.

What do you suggest?

Posted: Fri 02 Oct 2009 13:11
by AndreyR
As I have already mentioned, the entity should have a Version member.
Please set the IsVersion property to true for the property you wish to use as version in Entity Developer.
Please don't forget the database triggers on insert and update actions.

Posted: Sat 03 Oct 2009 06:32
by Falke
AndreyR wrote:As I have already mentioned, the entity should have a Version member.
Please set the IsVersion property to true for the property you wish to use as version in Entity Developer.
Please don't forget the database triggers on insert and update actions.
where can i set this property "IsVersion" ?

Posted: Mon 05 Oct 2009 07:11
by AndreyR
While editing the model in Entity Developer, just select the property you plan to mark as version member,
go to the Properties window and set IsVersion to true.