简体   繁体   English

流畅的NHibernate JoinedSubClass已经过时了

[英]Fluent NHibernate JoinedSubClass is obsolete

I wonder about something. 我不知道什么。 I'm sitting here with a solution there I have 1 superclass that has 2 subclasses and I'm currently mapping this using JoinedSubClass, but I get that this method is obsolete, and says that I should ClassMap and SubClassMap, but if I do this the AutoMapping does not work, and I don't want that. 我坐在这里有一个解决方案我有1个超类,有2个子类,我现在使用JoinedSubClass映射它,但我得知这个方法已经过时了,并说我应该使用ClassMap和SubClassMap,但如果我这样做AutoMapping不起作用,我不希望这样。 Is there any workaround for this? 这有什么解决方法吗?

Here's the hierarchy: 这是层次结构:

public class Tag : Entity
{

public virtual string Name {get;set;}
public virtual User User {get;set;}

}

public class RespondentTag : Tag
{
    public virtual IList<Respondent> Respondents {get;set;}
}


public class ArchiveTag : Tag
{
    public virtual IList<Survey> Surveys {get;set;}
}

As you probably figured out I want this to be a table per hierarchy-mapping with subclasses with lists that are Many-To-Many. 正如您可能想到的那样,我希望这是一个每个层次结构的表 - 映射与子类,列表是多对多。 Like a table 'Tag', then Tag_Respondent and Tag_Archive (for many-to-many relationship). 就像表'Tag',然后是Tag_Respondent和Tag_Archive(用于多对多关系)。

Here's the mapping that I'm currently using: 这是我目前正在使用的映射:

public class TagMap : IAutoMappingOverride<Tag>
{
  public void Override(AutoMapping<Tag> mapping)
  { 
     //This is obsolete
     mapping.JoinedSubClass("RespondentTagId", RespondentTagMap.AsJoinedSubClass());
     mapping.JoinedSubClass("ArchiveTagId", ArchiveTagMap.AsJoinedSubClass());

  }
}

public class RespondentTagMap
{
    public static Action<JoinedSubClassPart<RespondentTag>> AsJoinedSubClass()
    {
     return part =>

        part.HasManyToMany(x => x.RespondentList)
           .Cascade
           .SaveUpdate()
           .Inverse()
           .Table("Tag_Respondent");

    }
}


public class ArchiveTagMap
{
    public static Action<JoinedSubClassPart<ArchiveTag>> AsJoinedSubClass()
    {
     return part =>

        part.HasManyToMany(x => x.Surveys)
           .Cascade
           .SaveUpdate()
           .Inverse()
           .Table("Tag_Archive");

    }
}

Does anyone know about a workaround or another solution for solving this? 有没有人知道解决方法或解决此问题的其他解决方案? (Without disabling automapping) (不禁用自动化)

Any answers will be appreciated. 任何答案将不胜感激。

Thanks in advance! 提前致谢!

Forgive me if I'm misunderstanding your objective, but I'll take a stab at this since I have similar inheritance in my project (though I use a table-per-base-class pattern with a discriminator column). 如果我误解了你的目标,请原谅我,但是我会对此进行一次尝试,因为我的项目中有类似的继承(尽管我使用带有鉴别器列的每个基类表模式)。

I believe you can accomplish what you're looking to do by having FNH ignore your Tag base class, then overriding the mapping on your RespondentTag and ArchiveTag objects to implement the many-to-many relationship. 我相信你可以通过让FNH忽略你的Tag基类,然后覆盖你的RespondentTagArchiveTag对象上的映射来实现多对多关系来完成你想做的事情。 So in your FNH configuration, you'd specify an argument to your mappings call of: 因此,在您的FNH配置中,您需要为您的映射调用指定一个参数:

m.AutoMappings.Add(AutoMap.AssemblyOf<SomeObjectInMyAssembly>(new MyAutoMapConfig()) // Assuming you're using a config class
    .IgnoreBase(typeof(Entity))
    .IgnoreBase(typeof(Tag))
    .UseOverridesFromAssemblyOf<SomeOverrideClass>());

Then you'd have to set up overrides in whatever assembly you're storing them. 然后你必须在你存储它们的任何程序集中设置覆盖。 You'd have something like this: 你有这样的事情:

public class RespondentTagOverride : IAutoMappingOverride<RespondentTag>
{
    public void Override(AutoMapping<RespondentTag> mapping)
    {
        mapping.HasManyToMany(x => x.RespondentList)
            .Cascade
            .SaveUpdate()
            .Inverse()
            .Table("Tag_Respondent"); // Not sure if the table call works in the override...you may have to use a convention for this
    }
}

Same for the ArchiveTag object. ArchiveTag对象也是如此。

That's similar to what I do in my inheritance scheme, though as I mentioned, in my automap config class I override the IsDiscriminated method to indicate that my objects are table-per-base-class and discriminated. 这与我在继承方案中的操作类似,但正如我所提到的,在我的automap配置类中,我重写了IsDiscriminated方法,以指示我的对象是基于每个类的表并进行区分。

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

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