EntryEntities.Attach

EntryEntities.Attach

Postby Falke » Thu 24 Sep 2009 11:45

Is it possible to Attach objects to contexts?

context.EntryEntities.Attach(entity, true);

??
Falke
 
Posts: 9
Joined: Sun 06 Sep 2009 15:09

Postby AndreyR » Thu 24 Sep 2009 13:35

Yes, this method is supported.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby Falke » Wed 30 Sep 2009 07:17

how is the correct call? to detach and attach it? do you have a small example?
Falke
 
Posts: 9
Joined: Sun 06 Sep 2009 15:09

Postby AndreyR » Thu 01 Oct 2009 14:43

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.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby Falke » Thu 01 Oct 2009 20:33

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?
Falke
 
Posts: 9
Joined: Sun 06 Sep 2009 15:09

Postby AndreyR » Fri 02 Oct 2009 13:11

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.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby Falke » Sat 03 Oct 2009 06:32

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" ?
Falke
 
Posts: 9
Joined: Sun 06 Sep 2009 15:09

Postby AndreyR » Mon 05 Oct 2009 07:11

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.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16


Return to dotConnect for MySQL