Hi.

I have entity that had moved from one namespace to another, name and structure of entity don't changed.

Problem occurs when solution run in PerformSafely mode.

First of all, I don't see Unsafe action, but solution throwed ReferentialConstraintViolation.

I was disappointed, when see that I lost data in DB.

Created a test project. Bug repeated.

Test project:

namespace ConsoleApplication1
{
    using Xtensive.Orm;
    using Xtensive.Orm.Configuration;

    class Program
    {
        static void Main(string[] args)
        {
            var cfg = new DomainConfiguration("sqlserver", "Data Source=localhost; Initial Catalog=do40-tests; Integrated Security=True;")
            {
                UpgradeMode = DomainUpgradeMode.Recreate,
                ValidationMode = ValidationMode.OnDemand,
                NamingConvention = new NamingConvention { NamingRules = NamingRules.UnderscoreDots }
            };

            cfg.Sessions.Add(new SessionConfiguration("Default")
            {
                BatchSize = 25,
                DefaultIsolationLevel = SessionConfiguration.DefaultDefaultIsolationLevel,
                CacheSize = 1000,
                Options = SessionOptions.Default | SessionOptions.AutoTransactionOpenMode | SessionOptions.AutoTransactionSuppressMode
            });

            cfg.Types.Register(typeof(Program).Assembly);

            var domain = Domain.Build(cfg);

            var s = domain.OpenSession();
            s.Activate();

            // For recreate
            using (var tr = s.OpenTransaction())
            {
                var link = new EntityB { TestField = "EntityB" };

                new EntityA { TestField = "EntityA", TestLink = link };

                tr.Complete();
            }
        }
    }

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

    /// <summary>
    /// First entity
    /// </summary>
    [HierarchyRoot]
    public class EntityA : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

        /// <summary>
        /// TestField
        /// </summary>
        [Field]
        public string TestField { get; set; }

        /// <summary>
        /// TestLink
        /// </summary>
        [Field(Nullable = false)]
        public EntityB TestLink { get; set; }
    }
}

EntityB:

namespace ConsoleApplication1
{
    using Xtensive.Orm;

    /// <summary>
    /// Second entity
    /// </summary>
    [HierarchyRoot]
    public class EntityB : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

        /// <summary>
        /// TestField
        /// </summary>
        [Field]
        public string TestField { get; set; }
    }
}

Run solution.

Now change namespace for EntityB, add using to main file and set UpgradeMode = DomainUpgradeMode.PerformSafely

Run solution.

Exception:

SQL error occured.
Storage error details 'Entity: EntityB; Field: Id (FieldInfo);'
SQL error details 'Type: ReferentialConstraintViolation; Database: DO40-Tests; Table: EntityB; Column: Id; Constraint: FK_EntityA_TestLink_EntityB;'
Query 'ALTER TABLE [dbo].[EntityA] ADD CONSTRAINT [FK_EntityA_TestLink_EntityB] FOREIGN KEY ([TestLink_Id]) REFERENCES [dbo].[EntityB] ([Id]);'
Original message 'The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_EntityA_TestLink_EntityB". The conflict occurred in database "DO40-Tests", table "dbo.EntityB", column 'Id'.'

Go to DB and check data in table EntityB, it's empty!

However, adding RenameTypeHint fix situation, but i think erase data without warning it's huge bug!

DataObjects.Net v4.4.2

asked Feb 20 '12 at 01:36

Anton%20Guschin's gravatar image

Anton Guschin
73303035

edited Feb 23 '12 at 04:57

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Greetings, Anton.

I'll check this, thanks for the complete and well designed bug report.

BTW, does usage of NamingRules.UnderscoreDots influence somehow on the behavior?

(Feb 20 '12 at 04:21) Dmitri Maximov Dmitri%20Maximov's gravatar image

Yes. If remove NamingConvention from cfg initialization, then the test project run without errors.

(Feb 20 '12 at 04:58) Anton Guschin Anton%20Guschin's gravatar image

Thanks, that's important.

(Feb 20 '12 at 05:11) Dmitri Maximov Dmitri%20Maximov'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

powered by OSQA