Nhibernate 如何绘制地图?有一个x参考
我需要一个一个地做一个映射,我有一些疑问。我有以下课程:Nhibernate 如何绘制地图?有一个x参考,nhibernate,fluent-nhibernate,nhibernate-mapping,Nhibernate,Fluent Nhibernate,Nhibernate Mapping,我需要一个一个地做一个映射,我有一些疑问。我有以下课程: public class DocumentType { public virtual int Id { get; set; } /* othes properties for documenttype */ public virtual DocumentConfiguration Configuration { get; set; } public DocumentType () { }
public class DocumentType {
public virtual int Id { get; set; }
/* othes properties for documenttype */
public virtual DocumentConfiguration Configuration { get; set; }
public DocumentType () { }
}
public class DocumentConfiguration {
public virtual int Id { get; set; }
/* some other properties for configuration */
public virtual DocumentType Type { get; set; }
public DocumentConfiguration () { }
}
DocumentType对象只有一个DocumentConfiguration,但它不是一个继承对象,它只是一个接一个的唯一对象,用于分隔属性
在这种情况下,我的映射应该如何处理?我应该使用参考资料还是有参考资料?有人能举个例子吗
加载DocumentType对象时,我希望自动加载属性配置(在DocumentType中)
谢谢大家
干杯如果这段关系真的是一对一。。。然后使用HasOne:-)
看。它有您所需要知道的一切。即使您的域中有一对一,您的关系模型也可能是一对多。我怀疑您在两个表上共享相同的PK,更有可能在DocumentType的DocumentConfiguration上使用FK。在这种情况下,您将映射它,因为您映射的是您的关系模型。所以在DocumentType上,它将是HasOne.Inverse.AllDeleteOrphan。。。在文档配置上,它将是“参考” 现在,您应该在描述它时公开它
public class DocumentConfiguration
{
public DocumentConfiguration()
{
_internalDocumentConfigurations = new List<DocumentConfiguration>(1);
}
private IList<DocumentConfiguration> _internalDocumentConfigurations
public virtual DocumentType Type
{
get
{
return _internalDocumentConfigurations.FirstOrDefault();
}
/**/WARNING - no setter here**
}
public virtual SetDocumentConfiguration(DocumentConfiguration config)
{
//add your asserts here
Add(config);
}
private virtual Add (DocumentConfiguration config)
{
//add your asserts here
_internalDocumentConfigurations.Add(config)
config.DocumentType = this;
}
public virtual Remove (DocumentConfiguration config)
{
_internalDocumentConfigurations.Remove(config)
config.DocumentType = null;
}
是的,但是,如何使用?我应该在哪个映射类中使用?文档配置还是文档类型?我想做一个双向映射=/Thank Man两个类都应该有一对一。。。我建议在这种情况下使用主键关联。我将添加一个链接。
public class DocumentConfiguration {
public virtual int Id { get; set; }
/* some other properties for configuration */
public virtual DocumentType Type { get; protected internal set; }