Hi,

A sample is better than words :

[Serializable]
  [HierarchyRoot]
  public class MyEntity : Entity
  {
    [Field, Key]
    public int Id { get; private set; }

    [Field(Length = 100)]
    public string Text { get; set; }

    [Field]
    public string Text2
    {
      get
      {
        return text2;
      }
      set
      {
        text2 = value;
      }
    }
    private string text2;
  }

using (Session.Open(domain))
      {
        using (var transactionScope = Transaction.Open())
        {
          var helloWorld = new MyEntity
          {
            Text = "Hello World!", Text2 = "Hello!"
          };
          transactionScope.Complete();
        }
      }

      using (Session.Open(domain))
      {
        using (var transactionScope = Transaction.Open())
        {
          foreach (var myEntity in Query.All<MyEntity>())
            Console.WriteLine(myEntity.Text + " - " + myEntity.Text2);
          transactionScope.Complete();
        }
      }

Output

Hello World! -

It is seems property that are not automated properties are not persisted anymore.

I think this was working before : am I wrong?

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Jun 28 '10 at 15:11

olorin's gravatar image

olorin
358848792


One Answer:

psulek wrote:

[Field]
public string Text2
{
  get
  {
    return text2;
  }
  set
  {
    text2 = value;
  }
}
private string text2;

}

rewrite property "Text2" to this:

[Field]
public string Text2
{
  get { return GetFieldValue<string>("Text2"); }
  set { SetFieldValue("Text2", value); }
}

psulek wrote:

Thanks for the tip, psulek : this works like a charm. However I feel like I'm doing postsharp's job (but this may be normal) : can someone from Xtensive confirm?

What i know than this is exactly what postsharp generate when you use automatic properties like:

public string Text2 {get;set;}

then postsharp change it to something similar to my code above.


Alex (Xtensive) wrote:

Our PostSharp aspects are currently capable of processing only auto-properties. But we consider improving this in future so that this code:

public string Text2 {
  get { return GetFieldValue<string>("Text2"); }
  set { SetFieldValue("Text2", value); }
}

will be the following:

public string Text2 {
  get { return GetFieldValue<string>(); }
  set { SetFieldValue(value); }
}

I.e. we'll try to automatically rewrite special method calls in setters.

There is even a long-waiting issue for this: http://code.google.com/p/dataobjectsdot ... tail?id=75

answered Jun 28 '10 at 17:46

Editor's gravatar image

Editor
46153156157

olorin wrote: Thanks for the tip, psulek : this works like a charm.

However I feel like I'm doing postsharp's job (but this may be normal) : can someone from Xtensive confirm?

(Jun 28 '10 at 17:46) Editor Editor's gravatar image

olorin wrote: I think this is not a real issue, but that would be a nice feature :)

However this should be documented in manual.

(Jun 28 '10 at 17:46) Editor Editor'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:

×573

Asked: Jun 28 '10 at 15:11

Seen: 2,496 times

Last updated: Jun 28 '10 at 15:11

powered by OSQA