Fluent NHibernate JoinedSubClass 已过时
我想知道一些事情。我坐在这里有一个解决方案,我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我误解了你的目标,请原谅我,但我会尝试一下,因为我的项目中有类似的继承(尽管我使用带有鉴别器列的每基类表模式)。
我相信您可以通过让 FNH 忽略您的
Tag
基类,然后覆盖RespondentTag
和ArchiveTag
上的映射来完成您想要做的事情> 对象实现多对多关系。因此,在 FNH 配置中,您需要为映射调用指定一个参数:然后,您必须在存储它们的任何程序集中设置覆盖。你会有这样的东西:
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 yourRespondentTag
andArchiveTag
objects to implement the many-to-many relationship. So in your FNH configuration, you'd specify an argument to your mappings call of:Then you'd have to set up overrides in whatever assembly you're storing them. You'd have something like 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.