Why DateTime Version field is initialized with 0001.01.01 instead of DateTime.Now

DateTime.Now sets only after changing entity

Here is sample Code:

using System;
using System.Linq;
using Xtensive.Storage;
using Xtensive.Storage.Configuration;
using Project1.Model;

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

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

        [Field, Version]
        public DateTime Version { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var config = DomainConfiguration.Load("Default");
            var domain = Domain.Build(config);

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

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

            using (Session.Open(domain))
            {
                using (var transactionScope = Transaction.Open())
                {
                    var helloWorld = Query.All<MyEntity>().First();
                    helloWorld.Text += ".";
                    transactionScope.Complete();
                }
            }

            using (Session.Open(domain))
            {
                using (var transactionScope = Transaction.Open())
                {
                    foreach (var myEntity in Query.All<MyEntity>())
                        Console.WriteLine(myEntity.Version);
                    transactionScope.Complete();
                }
            }
            Console.ReadKey();
        }
    }
}

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

asked Jul 15 '10 at 12:15

pil0t's gravatar image

pil0t
207575763

To be fixed.

(Jul 15 '10 at 12:15) Alex Yakunin Alex%20Yakunin's gravatar image
Be the first one to answer this question!
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: Jul 15 '10 at 12:15

Seen: 2,180 times

Last updated: Jul 15 '10 at 12:15

powered by OSQA