异常? HasManyToMany NHibernate 映射
数据库结构:
Shows
ID
Name
Genres
ID
Name
ShowsGenres
ShowsID
GenresID
上面是我的数据库,我正在尝试找出如何正确映射它。我的 Show 对象是这样的:
public class Show
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
public virtual IList<Genre> Genres { get; set; }
}
我的 Genre 对象是:
public class Genre
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
public virtual IList<Show> Shows { get; set; }
}
我尝试了 HasManyToMany 的几种不同变体,但没有一个按照我想要的方式工作。
我需要能够删除节目以及与流派或多个流派的关系,但不能删除流派。
我需要能够删除某个类型及其与一个或多个节目的关系,但不能删除这些节目。
我该如何映射这个或者我需要尝试不同的东西?
更新:还要更多地考虑它,我还需要能够消除节目和流派之间的关系,而不删除节目或流派。
这是我的映射,但不确定它们是否正确。
HasManyToMany<Genre>(x => x.Genres)
.Table("ShowGenres")
.ParentKeyColumn("ShowID")
.ChildKeyColumn("GenreID");
HasManyToMany<Show>(x => x.Shows)
.Table("ShowGenres")
.ParentKeyColumn("GenreID")
.ChildKeyColumn("ShowID");
Database Strucutre:
Shows
ID
Name
Genres
ID
Name
ShowsGenres
ShowsID
GenresID
Above is my Database I am trying to figure out how to map this properly. My Show object is like this:
public class Show
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
public virtual IList<Genre> Genres { get; set; }
}
My Genre Object is:
public class Genre
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
public virtual IList<Show> Shows { get; set; }
}
I have tried several different varations of HasManyToMany, but none work the way I want them to.
I need to be able to delete a show and the relationship with the genre, or many genres, but not delete the genre(s).
I need to be able to delete a genre and its relationship with a show, or many shows, but not delete the show(s).
How can I map this or do I need to try something differently?
Update: Also thinking about it more I would also need to be able to remove the relationship between a show and a genre without removing the show or the genre.
Here are my mappings I have, but not exactly sure they are correct.
HasManyToMany<Genre>(x => x.Genres)
.Table("ShowGenres")
.ParentKeyColumn("ShowID")
.ChildKeyColumn("GenreID");
HasManyToMany<Show>(x => x.Shows)
.Table("ShowGenres")
.ParentKeyColumn("GenreID")
.ChildKeyColumn("ShowID");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一篇旧帖子,但我基本上有同样的问题。在这里回答:
HasManyToMany Fluent NHibernate 映射删除错误
This is an old post but I basically had the same question. Answered here:
HasManyToMany Fluent NHibernate Mapping Delete Error