EntryEntities.Attach

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
Falke
Posts: 9
Joined: Sun 06 Sep 2009 15:09

EntryEntities.Attach

Post by Falke » Thu 24 Sep 2009 11:45

Is it possible to Attach objects to contexts?

context.EntryEntities.Attach(entity, true);

??

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 24 Sep 2009 13:35

Yes, this method is supported.

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

Post by Falke » Wed 30 Sep 2009 07:17

how is the correct call? to detach and attach it? do you have a small example?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by 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.

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

Post by 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?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by 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.

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

Post by 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" ?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by 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.

Post Reply