For example, we have subscription on two DO session events

            session.Events.EntitySetItemRemoveCompleted += (o, eventArgs) =>
            {
                Changes.Add("Remove item from " + eventArgs.Field.Name);
            };

            session.Events.EntitySetItemAddCompleted += (o, eventArgs) =>
            {
                Changes.Add("Add new item in " + eventArgs.Field.Name);
            };

Now run following code

    static void Main(string[] args)
    {
        var connectionString = "Data Source=.; Initial Catalog=DO40-Tests; Integrated Security=True;";
        var dc = new DomainConfiguration("sqlserver", connectionString);

        //dc.UpgradeMode = DomainUpgradeMode.Recreate;
        dc.UpgradeMode = DomainUpgradeMode.Recreate;

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

        using (var d = Domain.Build(dc))
        {
            using (var s = d.OpenSession())
            using (s.Activate())
            using (var t = s.OpenTransaction())
            {
                var owner = new Table { Name = "1" };

                Module.Changes.Add("---Create Tp1");

                var tp1 = new Tp1 { Owner = owner };

                Module.Changes.Add("---Create Tp2");

                var tp2 = new Tp2 { Owner = owner };

                Module.Changes.Add("---Create Tp3");

                var tp3 = new Tp3 { Owner = owner };

                Module.Changes.Add("---Create Tp4");

                var tp4 = new Tp4 { Owner = owner };

                Module.Changes.Add("---Remove Tp4");

                tp4.Remove();

                Module.Changes.Add("---Remove Tp3");

                tp3.Remove();

                Module.Changes.Add("---Remove Tp2");

                tp2.Remove();

                Module.Changes.Add("---Remove Tp1");

                tp1.Remove();

                t.Complete();
            }

            foreach (var change in Module.Changes)
            {
                Console.WriteLine(change);
            }

            Console.ReadKey();
        }
    }
}

public class Module : IModule
{
    public static List<string> Changes = new List<string>();

    /// <summary>
    /// Called when 'complex' build process is completed.
    /// </summary>
    /// <param name="domain">The built domain.</param>
    public void OnBuilt(Domain domain)
    {
        domain.SessionOpen += (sender, args) =>
        {
            var session = args.Session;

            session.Events.EntitySetItemRemoveCompleted += (o, eventArgs) =>
            {
                Changes.Add("Remove item from " + eventArgs.Field.Name);
            };

            session.Events.EntitySetItemAddCompleted += (o, eventArgs) =>
            {
                Changes.Add("Add new item in " + eventArgs.Field.Name);
            };
        };
    }

    /// <summary>
    /// Called when the build of <see cref="T:Xtensive.Orm.Building.Definitions.DomainModelDef"/> is completed.
    /// </summary>
    /// <param name="context">The domain building context.</param><param name="model">The domain model definition.</param>
    public void OnDefinitionsBuilt(BuildingContext context, DomainModelDef model)
    {
    }
}

[HierarchyRoot]
[Serializable]
public class Table : Entity
{
    [Field, Key]
    public Guid Id { get; set; }

    [Field(Length = 10)]
    public string Name { get; set; }

    [Field]
    [Association(PairTo = "Owner", OnTargetRemove = OnRemoveAction.Clear)]
    public EntitySet<Tp1> Tp1 { get; set; }

    [Field]
    [Association(PairTo = "Owner", OnTargetRemove = OnRemoveAction.Clear)]
    public EntitySet<Tp2> Tp2 { get; set; }

    [Field]
    [Association(PairTo = "Owner", OnTargetRemove = OnRemoveAction.Clear)]
    public EntitySet<Tp3> Tp3 { get; set; }
}

[HierarchyRoot]
[Serializable]
public class Tp1 : Entity
{
    [Field, Key]
    public Guid Id { get; set; }

    [Field(Length = 10)]
    public Table Owner { get; set; }
}

[Serializable]
public class Tp2 : Tp1
{
}

[Serializable]
public class Tp3 : Tp2
{
}

[Serializable]
public class Tp4 : Tp3
{
}

Output:

---Create Tp1
Add new item in Tp1
---Create Tp2
Add new item in Tp2
---Create Tp3
Add new item in Tp3
---Create Tp4
Add new item in Tp1
---Remove Tp4
Remove item from Tp3
Remove item from Tp2
---Remove Tp3
Remove item from Tp3
Remove item from Tp2
---Remove Tp2
Remove item from Tp2
---Remove Tp1
Remove item from Tp1

Questions:

  1. Why, when element removed, event rising several times, when created just once?

  2. Why Tp4 creation rise event for field Tp1?

  3. Why, when elements Tp4, Tp3, Tp2 removed, event for Tp1 not rise?

asked Oct 27 '15 at 02:35

Anton%20Guschin's gravatar image

Anton Guschin
73223035


One Answer:

Thank you Anton for the report. We'll investigate the problem.

answered Dec 14 '15 at 03:55

Alexey%20Kulakov's gravatar image

Alexey Kulakov
45215

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:

×568
×3

Asked: Oct 27 '15 at 02:35

Seen: 5,069 times

Last updated: Dec 14 '15 at 03:55

powered by OSQA