Fluent NHibernate JoinedSubClass 已过时

发布于 2024-09-11 02:12:01 字数 1663 浏览 3 评论 0原文

我想知道一些事情。我坐在这里有一个解决方案,我有 1 个超类,它有 2 个子类,我目前正在使用 JoinedSubClass 映射它,但我知道这个方法已经过时了,并说我应该使用 ClassMap 和 SubClassMap,但如果我这样做自动映射不起作用,我不希望这样。有什么解决方法吗?

这是层次结构:

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;}
}

正如您可能想到的那样,我希望这是每个层次结构映射的一个表,其子类具有多对多的列表。就像表“Tag”一样,然后是 Tag_Respondent 和 Tag_Archive(对于多对多关系)。

这是我当前正在使用的映射:

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");

    }
}

有谁知道解决此问题的解决方法或其他解决方案? (在不禁用自动映射的情况下)

任何答案将不胜感激。

提前致谢!

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. 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).

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海未深 2024-09-18 02:12:01

如果我误解了你的目标,请原谅我,但我会尝试一下,因为我的项目中有类似的继承(尽管我使用带有鉴别器列的每基类表模式)。

我相信您可以通过让 FNH 忽略您的 Tag 基类,然后覆盖 RespondentTagArchiveTag 上的映射来完成您想要做的事情> 对象实现多对多关系。因此,在 FNH 配置中,您需要为映射调用指定一个参数:

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

然后,您必须在存储它们的任何程序集中设置覆盖。你会有这样的东西:

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
    }
}

ArchiveTag 对象也是如此。

这与我在继承方案中所做的类似,不过正如我所提到的,在我的自动映射配置类中,我重写了 IsDiscriminated 方法以指示我的对象是按基类表并进行区分的。

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. So in your FNH configuration, you'd specify an argument to your mappings call of:

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文