Hello,

I am using DO.Net 4.4.0 and I have following entity:

[HierarchyRoot] public class Content : Entity {

...

[Field(Length = 1024, DefaultValue = "", Nullable = false)] [NotNullConstraint] public string Description { get; set; }

[Field(Nullable = false),Version(VersionMode.Skip)] public DateTime DateAccessed { get; set; }

[Field, Version(VersionMode.Auto)] public int Version { get; private set; }

}

What I'am trying to achieve is:

  1. When Content.Description is changed, Content.Version and Content.VersionInfo should be changed automatically - which is working as expected

  2. When Content.DateAccessed is changed, Content.Version and Content.VersionInfo should NOT be changed, which is not working right now

As a workaround right now I just removed the Content.Version from the entity, and it is working as expected. The problem is network traffic - entity objects are mapped to DTO objects and transferred over the network. The VersionInfo duplicates the traffic, because all fields which is part of the version are basically transferred twice.

So, the question is: It is possible to define single field to hold entity version and define fields for which it should or should not be automatically incremented on value change?

Many thanks.

asked Apr 25 '12 at 11:52

pub's gravatar image

pub
7113

edited Apr 25 '12 at 12:10

Btw, you can use 4 space indent to get fixed width font and syntax highlighting

(Apr 26 '12 at 08:04) Denis Krjuchkov Denis%20Krjuchkov's gravatar image

One Answer:

Hello pub,

DataObjects.Net chooses version fields using the following algorithm:

1) If no field is marked with [Version(VersionMode.Auto)] or [Version(VersionMode.Manual)] all fields are used as version except fields that are lazy-loaded and fields that has VersionMode.Skip

2) If some field is marked with version attribute in Auto or Manual mode, only specified fields are considered version.

[Version(VersionMode.Skip)] does not affect calculation of automatic versions. Those are updated when any fields is changed.

To get desired behaviour you can override UpdateVersion() method and control when to update automatic version fields:

protected override bool UpdateVersion(Entity changedEntity, FieldInfo changedField)
{
  // Returning false tells framework to keep current version
  if (changedField.SkipVersion)
    return false;
  // Base implementation increments all VersionMode.Auto fields
  // and returns true. This causes version tuple to be recalculated.
  return base.UpdateVersion(changedEntity, changedField);
}

Probably changes of [Version(VersionMode.Skip)] fields should not trigger increment of auto-version fields, but that would break existing code. We'll consider how current behaviour could be improved.

answered Apr 26 '12 at 08:03

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

edited Apr 26 '12 at 09:12

I found a serious issue about this method: UpdateVersion is called even oldValue and newValue are same! This means that the version is updated even OnSettingFieldValue is not called. Is it possible to execute UpdateVersion logic inside OnSettingFieldValue and then manually recalculate version tuple?

(Jun 01 '12 at 06:56) pub pub's gravatar image

You can call UpdateVersionInfo() any time you want to update version tuple (it will call your UpdateVersion() method). However for the moment it's not possible to avoid calling UpdateVersionInfo() when the same value is assigned, we'll likely to provide bug fix for that.

(Jun 04 '12 at 10:19) Denis Krjuchkov Denis%20Krjuchkov'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

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×574
×5
×2

Asked: Apr 25 '12 at 11:52

Seen: 3,949 times

Last updated: Jun 04 '12 at 10:19

powered by OSQA