NHibernate 映射问题
CREATE TABLE IF NOT EXISTS `movie` (
`m_ID` varchar(9) NOT NULL
`ReleaseDate` date
`Title` varchar(255) NOT NULL
PRIMARY KEY (`m_ID`),
KEY `m_ID` (`ReleaseDate`,`Title`,)
)
CREATE TABLE IF NOT EXISTS `m_director` (
`dirID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`dirName` varchar(40) NOT NULL,
PRIMARY KEY (`dirID`),
UNIQUE KEY `dirName` (`dirName`)
)
CREATE TABLE IF NOT EXISTS `m_directs` (
`m_ID` char(9) NOT NULL
`dirID` int(11) unsigned NOT NULL,
UNIQUE KEY `m_ID_2` (`m_ID`,`dirID`),
KEY `m_ID` (`m_ID`),
KEY `dirID` (`dirID`)
)
另请注意,m_ID 设置为 movie 表的外键,dirID 设置为 m_director 的外键。
我不明白如何通过映射 xml 将其映射到这样的对象。
public class Movie
{
public string MovieTitle{get;set;}
public IList<string> Directors;
public DateTime ReleaseDate;
}
我可以看到,如果 movie 和 m_director (例如 m_directs)之间没有中间表,那么使用列表标记会相当容易,但是对于像我这样的模式,我不明白这是如何完成的。
CREATE TABLE IF NOT EXISTS `movie` (
`m_ID` varchar(9) NOT NULL
`ReleaseDate` date
`Title` varchar(255) NOT NULL
PRIMARY KEY (`m_ID`),
KEY `m_ID` (`ReleaseDate`,`Title`,)
)
CREATE TABLE IF NOT EXISTS `m_director` (
`dirID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`dirName` varchar(40) NOT NULL,
PRIMARY KEY (`dirID`),
UNIQUE KEY `dirName` (`dirName`)
)
CREATE TABLE IF NOT EXISTS `m_directs` (
`m_ID` char(9) NOT NULL
`dirID` int(11) unsigned NOT NULL,
UNIQUE KEY `m_ID_2` (`m_ID`,`dirID`),
KEY `m_ID` (`m_ID`),
KEY `dirID` (`dirID`)
)
Also note that m_ID is set as a foreign key to movie table and dirID is set as a foreign key to m_director.
I do not understand how this would get mapped to an object like this one via mapping xmls.
public class Movie
{
public string MovieTitle{get;set;}
public IList<string> Directors;
public DateTime ReleaseDate;
}
I can see it would be fairly easy with a list tag if there was not an intermediary table between movie and m_director(eg m_directs), but for a schema like I have, I do not understand how this is done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK
public IList;导演;
不能是多个,因为字符串没有对象标识,因此无法从不同的电影链接。因此你不能用 NHibernate 来映射它。最好的方法是向董事提供更多信息,例如出生日期等。
编辑:更正了 xml 映射的拼写错误和缩进(因此未显示)并添加了流畅的映射
AFAIK
public IList<string> Directors;
cant be a manytomany because string has no object identity so it cant be linked from different Movies. Therefor you cant map it with NHibernate as manytomany. best way would be tothen it would be also possible to give directors more information like Birthdate and so on.
Edited: corrected typos and indentation of xml mapping (hence not shown) and added fluent mapping