I use DataObjects.Net v4.4.0 Beta 1

In App.config

<domain name="Default" upgradeMode="Recreate" connectionUrl="sqlserver://localhost

MyEntity.cs

using System;
using Xtensive.Orm;

namespace BugTest.Model
{

    [Serializable]
    [HierarchyRoot]
    public abstract class SomeEntity : Entity
    {
        protected SomeEntity(Session session) : base(session)
        {
        }

        [Field, Key]
        public int Id { get; private set; }

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

    [Serializable]
    public class FirstEntity : SomeEntity
    {
        public FirstEntity(Session session) : base(session)
        {
        }

        [Field]
        [Association(PairTo = "Owner")]
        public EntitySet<FirstChild> entSet { get; set; }
    }

    [Serializable]
    public class SecondEntity : SomeEntity
    {
        public SecondEntity(Session session) : base(session)
        {
        }

        [Field]
        [Association(PairTo = "Owner")]
        public EntitySet<SecondChild> entSet { get; set; }
    }

    [Serializable]
    public class MyEntity<TEntity> : Entity where TEntity : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

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

        [Field]
        public TEntity Owner { get; set; }

        public MyEntity(Session session, TEntity entity)
            : base(session)
        {
            Owner = entity;
        }

        public MyEntity(Session session)
            : base(session)
        {
        }
    }

    [Serializable]
    [HierarchyRoot]
    public abstract class NextEntity : MyEntity<SomeEntity>
    {
        public NextEntity(Session session) : base(session)
        {
        }

        protected NextEntity(Session session, SomeEntity entity) : base(session, entity)
        {
        }
    }

    [Serializable]
    public class FirstChild : NextEntity
    {
        public FirstChild(Session session, SomeEntity entity) : base(session, entity)
        {
        }

        public FirstChild(Session session) : base(session)
        {
        }
    }

    [Serializable]
    public class SecondChild : NextEntity
    {

        public SecondChild(Session session)
            : base(session)
        {
        }

        public SecondChild(Session session, SomeEntity entity) : base(session, entity)
        {
        }
    }
}

Program.cs

using System;
using System.Linq;
using Xtensive.Orm;
using Xtensive.Orm.Configuration;
using BugTest.Model;

namespace BugTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Loading configuration section for in-memory database. 
            // See other cases in App.config file.
            var config = DomainConfiguration.Load("Default");
            var domain = Domain.Build(config);

            using (var session = domain.OpenSession())
            {
                using (var transactionScope = session.OpenTransaction())
                {
                    // Creating new persistent object
                    var first = new FirstEntity(session)
                    {
                        Text = "first!"
                    };

                    // Creating new persistent object
                    var second = new SecondEntity(session)
                    {
                        Text = "second!"
                    };

                    new FirstChild(session, first) { Text = "First" };
                    new SecondChild(session, second) { Text = "Second" };

                    // Committing transaction
                    transactionScope.Complete();
                }
            }

            using (var session = domain.OpenSession())
            {
                using (var transactionScope = session.OpenTransaction())
                {
                    Console.WriteLine(session.Query.All<SecondChild>().First().Text);
                    Console.WriteLine(session.Query.All<FirstChild>().First().Text);
                }
            }

            Console.ReadKey();
        }
    }
}

But if I use in App.config

<domain name="Default" upgradeMode="Recreate" connectionUrl="memory://localhost

Everything works fine. I think this is your bug.

asked Apr 28 '11 at 02:33

Multysh's gravatar image

Multysh
15669

edited Apr 28 '11 at 02:54

Hello Multysh,

What is the purpose of using 4.4 beta 1 when the final 4.4 version is already released? Could you please upgrade to the latest version and check whether the case still presents.

(Apr 28 '11 at 03:51) Dmitri Maximov Dmitri%20Maximov's gravatar image

I update to 4.4 with revision 7460

Bug not fix

(Apr 28 '11 at 04:06) Multysh Multysh's gravatar image

Thanks.

Will check this.

(Apr 28 '11 at 04:07) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

Multysh,

Am I right saying that the problem is in ReferentialConstraintViolationException while DataObjects.Net tries persisting the whole object graph?

If yes, then try disabling foreign keys as a temporary workaround. It can be done this way:

<domain name="default"
  connectionUrl="..." foreignKeyMode="None"/>

When the bug is fixed, I'll notify you.

BTW, thanks for the test case, it really helped to identify the trouble in seconds.

answered Apr 28 '11 at 05:07

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

edited Apr 28 '11 at 05:07

1

Thanks for the quick response

(Apr 28 '11 at 08:08) Multysh Multysh's gravatar image

Fixed in revision 7496. Nightly build will be available soon in download section.

(May 11 '11 at 10:16) Dmitri Maximov Dmitri%20Maximov'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
×10
×5

Asked: Apr 28 '11 at 02:33

Seen: 4,679 times

Last updated: May 11 '11 at 10:16

powered by OSQA