I got into some impediments with running search on our db. We have some historical solution where it was decided to use ConcreteTable schema for one of the hierarchies where we got more that hundred of descendants and it was working fine. But now we need to do full text search on one of the field of base abstract class and it turns out that Full text attribute is not supported fot this setup. So we decided to try to migrate ConcreteTable to SingleTable. But Domain.Build(config) is failing with exception "An item with the same key has already been added." with out any further information. I created test case scenario with one abstract base class and two descendants and got this same issue.

[Serializable]
[HierarchyRoot(InheritanceSchema.ConcreteTable)]
public class BaseClass : Entity, INamed
{
    protected BaseClass(Session session)
        : base(session)
    {
        Created = DateTime.Now;
    }

    [Field]
    public DateTime? Created { get; private set; }

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

    [Field]
    public string Name { get; set; }

    [Field]
    public string BaseClassFieldA { get; set; }

    [Field]
    public string BaseClassFieldB { get; set; }
}

public class ConcreetClassA : BaseClass
{
    public ConcreetClassA(Session session): base(session){}
}

public class ConcreetClassB : BaseClass
{
    public ConcreetClassB(Session session): base(session){}
}

To reproduce an issue you can build domain with ConcreteTable, check that two tables were created. Then change InheritanceSchema to SingleTable and try to build it again.

I believe that I have to add some Hints to UpgradeHandler but I haven't found any info on which ones to use for this case and blidly trying different existing Hints was not working for me. Can you please help me how to do such a migration?

asked Jun 25 '20 at 07:23

Mikhail's gravatar image

Mikhail
5111


4 Answers:

In my case there are 130 of descendants. I decided to not to merge all of them into one super table because it will then contain more than 300 columns. What I choose instead is to have one table with just basic columns and all of the deviations from concreet classes I'll store in another table with connection table one to many. Unfortunatelly to do so I'll have to write migration sql script to manually migrate all the existing data to a new scheema.

answered Jul 07 '20 at 08:48

Mikhail's gravatar image

Mikhail
5111

By saying "empty" I meant that there are no any fields in descendant classes. Changing type of hierarchy is very hard process due to a lot of changes and now data should be manually migrated by user because in some cases it is not trivial migrations.

I'm preparing a full example of how to migrate based on a hierarchy which contains 7 entities - binary tree with three levels. Such example hierarchy should be representative enough. I assume that you have some references to the current hierarchy items and this is main problem to solve in my example. But if this ConcreteTable hierarchy happens to have no references to any of its entities from another hierarchies i can give my example right now.

answered Jul 07 '20 at 03:54

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

Hi Alexey,

If all inheritants are empty it is relatively easy to do If you mean just delete concret tables and framework will create new sombined one then yes. But in my case those concret tables are filled. but not with hints. I am not sure if they are. Please tell me whether they are I'm new to the framework and I'm not that familiar with available hints but non of them looked like they are applicable to migrate InheritanceSchema

answered Jul 03 '20 at 03:58

Mikhail's gravatar image

Mikhail
5111

Hello Mikhail,

Unfortunately it is bug and it is not so easy to workaround it. If all inheritants are empty it is relatively easy to do, but not with hints. I am not sure if they are. Please tell me whether they are. Based on that i will be able to give you the way that fits your case more.

answered Jul 01 '20 at 09:44

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

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:

×5
×2
×2
×2

Asked: Jun 25 '20 at 07:23

Seen: 1,484 times

Last updated: Jul 07 '20 at 08:48

powered by OSQA