Hi,

I'm trying to use DO.net with an .Net ObjectDataSource in a disconnected state. The classes being used with the ObjectDataSource creates a new entity when constructed in a disconnected state, but how do I reflect property changes and then commit back to the DB?

Scenario for code below: The ODS calls a static method and grabs an new UiEndUser and populates the fields on a formview of a webform based on the wrapped EndUser entity public properties. When sumbit on the formview is called, the properties are set with the populated data in the formview on the webform and a static method is called again by the ODS

Code:

public class UiEndUser : UiWrapper<Model.EndUser>
{
    public Guid Id
    {
        get { return entity.Id; }
    }

    public DateTime MoveInDate
    {
        get { return entity.MoveInDate; }
        set { entity.MoveInDate = value; }
    }
}

public class UiWrapper<T> where T : Entity, new()
{
    public UiWrapper()
    {
        DState = new DisconnectedState();

        using (var session = Session.Open(DomainBuilder.GetCurrentDomain()))
        {
            using (DState.Attach(session))
            {
                entity = Model.Factory<T>.Create();
            }
        }
    }
}

asked Aug 25 '10 at 05:24

Carl's gravatar image

Carl
23448

edited Sep 06 '10 at 04:56

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Basically I am looking for the scenario described in:

http://blog.dataobjects.net/2009/06/disconnected-offline-entities-poco-and.html

2) A wizard in ASP.NET application that must make a set of changes through a set of postbacks, but they must be really flushed into the storage only on the final wizard page.

(Aug 26 '10 at 03:02) Carl Carl's gravatar image

I wanted to ask why do you use DisconnectedState at all here, but now it's clear the choice is correct.

(Aug 26 '10 at 03:09) Alex Yakunin Alex%20Yakunin's gravatar image

One Answer:

DisconnectedState has some changes to apply, when disconnectedState.Operations.Count != 0.

Note that assignments of the same value to some properties are also logged in this case, i.e. code like someEntity.someProperty = someEntity.someProperty will lead to addition of operation in disconnectedState.Operations. This is correct, since we check versions of all the changed entities when log is replayed, so if this operation won't be logged, and some other user would change the value of someEntity.someProperty concurrently, we won't notice this on ApplyChanges.

I.e. you could see someEntity.someProperty != someEntity.someProperty after applying the changes, that generally isn't expected. Expected result is:

  • either someEntity.someProperty == someEntity.someProperty
  • or there was an exception on ApplyChanges (VersionCOnflictException in case someone else has changed this property).

So if you need to avoid setting of properties to the same values (btw, may be that's exactly what is necessary), you must assign them only if their values are really changed.

answered Aug 26 '10 at 03:08

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

edited Aug 26 '10 at 03:12

I have the correct count in operations now, but changes don't appear in subsequent queries after calling applychanges. My issues before was that I was using ambient transactions in other areas, so I setup a separate domain setting in the app config for the disconnected. No key seems to be returned from the applychanges call either

(Aug 26 '10 at 07:51) Carl Carl's gravatar image

Do you commit the transaction in Session, to which ApplyChanges applies the changes (if that transaction is manually created)?

(Aug 26 '10 at 08:56) Alex Yakunin Alex%20Yakunin's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA