简体   繁体   English

派生类中的对象引用数据库中的基类,而不是派生类

[英]Objects in derived class reference base class in database, instead of derived class

(When I say a record "has" another record, by that I mean the other record has a reference to the first). (当我说一个记录“有”另一个记录时,是指另一个记录引用了第一个记录)。

I have the following database relationship: 我有以下数据库关系:

Tables 桌子

BaseAnswer -> MultipleChoiceAnswer -> MultipleChoiceAnswerCulture BaseAnswer-> MultipleChoiceAnswer-> MultipleChoiceAnswerCulture

A BaseAnswer record can have a MultipleChoiceAnswer record. BaseAnswer记录可以具有MultipleChoiceAnswer记录。 For each "MultipleChoiceAnswer" there are several "Culture" records: 对于每个“ MultipleChoiceAnswer”,都有几个“ Culture”记录:

Records 记录

English Title 英文标题

French Title 法国头衔

A MultipleChoiceAnswer record has a column that refers to the BaseAnswer's primary key, and likewise the records in MultipleChoiceAnswerCulture have a column that should refer to the MultipleChoiceAnswer's primary key. 一个MultipleChoiceAnswer记录有指BaseAnswer的主键列,并同样MultipleChoiceAnswerCulture记录有参照MultipleChoiceAnswer的主键列。 However, my problem is that the records being inserted into MultipleChoiceAnswerCulture are referring to the BaseAnswer's primary key instead (the root parent, not the direct parent). 但是,我的问题是,插入到MultipleChoiceAnswerCulture的记录是引用BaseAnswer的主键(根父级,而不是直接父级)。 Here is my code: 这是我的代码:

public class MultipleChoiceAnswerMap : SubclassMap<MultipleChoiceAnswer>
{
    public MultipleChoiceAnswerMap() 
    {            
        Table("MultipleChoiceAnswer");
        KeyColumn("BaseAnswerID");
        Map(x => x.Score);

        HasMany(x => x.Resources)
            .CollectionType<ResourceMapSetUserType<MultipleChoiceAnswerCulture>>()
            .KeyColumn("MultipleChoiceAnswerID")
            .Cascade.AllDeleteOrphan()
            .Access.CamelCaseField(Prefix.Underscore)
    }

} }

We have another example in one of our projects that is similar to this, and even though I'm working off of that, this still keeps inserting the BaseAnswer's primary key as a reference instead of the MultipleChoiceAnswer's primary key, in the MultipleChoiceAnswerCulture table. 在我们的一个项目中,我们有一个与此类似的示例,即使我正在解决这个问题,它仍然继续在MultipleChoiceAnswerCulture表中插入BaseAnswer的主键作为参考,而不是MultipleChoiceAnswer的主键。

Any help would be appreciated. 任何帮助,将不胜感激。

Alright well, we've looked into it, and apparently the code I was working off of most likely suffered the same issue. 好吧,我们已经研究了它,显然我正在研究的代码很可能遇到了同样的问题。 We're probably going to just go ahead and let the foreign key in MultipleChoiceAnswerCulture be a reference to the root parent after all. 我们可能将继续进行下去,毕竟让MultipleChoiceAnswerCulture中的外键成为对根父代的引用。 If anyone does in fact know how to solve this, I'd appreciate it if you posted it here. 如果有人确实知道如何解决此问题,请将它张贴在这里,我将不胜感激。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM