Fluent nhibernate 如何使用fluent nhibernate在多对多关系中设置键列
我使用的是flunet nhibernate,在多对多关系中,我需要在这两个实体之间的表中有键列Fluent nhibernate 如何使用fluent nhibernate在多对多关系中设置键列,fluent-nhibernate,Fluent Nhibernate,我使用的是flunet nhibernate,在多对多关系中,我需要在这两个实体之间的表中有键列 HasManyToMany(p => p.Signers) //.Cascade.AllDeleteOrphan() .Table("PersonnelDocumentSigner") .Schema("personnel"); public partial class PersonnelDocument {
HasManyToMany(p => p.Signers)
//.Cascade.AllDeleteOrphan()
.Table("PersonnelDocumentSigner")
.Schema("personnel");
public partial class PersonnelDocument
{
private IList<Position> _signers;
virtual public IList<Position> Signers
{
get
{
if (_signers == null)
_signers = new List<Position>();
return _signers;
}
set
{
_signers = value;
}
}
}
创建的表只包含以下两列:PersonnelDocumentId、PositionId
但我需要此连接器表PersonnelDocumentSigner的列Id
如何准确地分配它?像PersonnelDocumentSigner这样的链接表通常不需要Id列,因为PersonnelDocumentId和PositionId一起是Id/主键。如果仍希望在链接表中包含其他数据,则应创建一个新实体
class PersonnelDocumentSigner
{
public virtual PersonnelDocument Document { get; set; }
public virtual Position Signer { get; set; }
public virtual int Id { get; set; }
// additional Properties
}
class PersonnelDocumentSignerMap : ClassMap<PersonnelDocumentSigner>
{
Table("PersonnelDocumentSigner");
CompositeId()
.KeyReference(pds => pds.Document)
.KeyReference(pds => pds.Signer);
Map(pds => pds.Id);
// additional Mapps
}