Fluent Nhibernate引用具有多列的(非主要)外键

时间:2018-03-22 15:02:45

标签: nhibernate fluent-nhibernate nhibernate-mapping fluent-nhibernate-mapping

我在将引用映射到具有多列的(非主要)外键时遇到问题,我收到此错误,因为Nhibernate基于主键引用:

Foreign key (FK46A50409849F9B22:OrganizationObjects [Identificator, fromDate])) must have same number of columns as the referenced primary key (OrganizationObjects [Id]) 

我想引用多个列,PropertyRef只支持一个列名。 这是约束:

CONSTRAINT organizationobjectsparentposition FOREIGN KEY (identificator, fromdate)
      REFERENCES hr.organizationobjects (identificator, fromdate) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT unique_identificator_fromdate UNIQUE (identificator, fromdate)

班级:

public class OrganizationObject
    {
        public virtual Guid Id { get; set; }

        public virtual Guid? Identificator { get; set; }
        public virtual OrganizationObjectTypeEnum Type { get; set; }
        public virtual string Name { get; set; }
        public virtual string Index { get; set; }
        public virtual Company Company { get; set; }
        public virtual Job Job { get; set; }
        public virtual OrganizationObject Parent { get; set; }
        public virtual DateTime FromDate { get; set; }
        public virtual DateTime? ToDate { get; set; }
        public virtual CostCenter CostCenter { get; set; }
        public virtual string Level { get; set; }
        public virtual OrganizationObject ParentPosition { get; set; }
        public virtual Location Location { get; set; }
        public virtual Employee.Employee Employee { get; set; }
        public virtual JobDescription Description { get; set; }
        public virtual IList<WorkingPositionCompetence> WorkingPositionCompetences { get; set; }

        public static OrganizationObject New()
        {
            var organizationObject = new OrganizationObject
            {
                Id = GuidComb.NewGuid(),
                WorkingPositionCompetences = new List<WorkingPositionCompetence>()
            };

            return organizationObject;
        }
    }

和mappping:

internal OrganizationObjectMap()
        {
            Schema("HR");
            Table("OrganizationObjects");

            Id(x => x.Id).GeneratedBy.Assigned();

            Map(x => x.Identificator);
            Map(x => x.Type);
            Map(x => x.Name);
            Map(x => x.Index);
            Map(x => x.FromDate);
            Map(x => x.ToDate);
            Map(x => x.Level);

            References(x => x.Company, "CompanyId");
            References(x => x.Job, "JobId");
            References(x => x.Parent, "ParentId");
            References(x => x.CostCenter, "CostCenterId");
            References(x => x.ParentPosition).Columns("Identificator", "fromDate").PropertyRef("Identificator", "fromDate"); // Unsuported!?
            References(x => x.Location, "LocationId");
            References(x => x.Employee, "EmployeeId");

            HasOne(x => x.Description).Cascade.All().PropertyRef("OrganizationObject");
            HasMany(x => x.WorkingPositionCompetences).KeyColumn("OrganizationObjectId").Inverse().Cascade.AllDeleteOrphan();

        }

0 个答案:

没有答案