Skip to content

The column 'Contract' has already been added in this SQL builder when upgrading to NH 5.2.3 #2001

Closed
@marcmognol

Description

@marcmognol

Hi,

Thank you for your help !

Since i tried to upgrade NuGet package of NHibernate from 5.1.4 to 5.2.3 I have the following error message when session is created:

The column 'Contract' has already been added in this SQL builder

Below, mapping and models of my two entities:

public class WorkCenterDepartmentMap : ClassMap<WorkCenterDepartment>
{
	public WorkCenterDepartmentMap()
	{
		Table("WORK_CENTER_DEPARTMENT");

		CompositeId().KeyProperty(x => x.Contract, "CONTRACT")
					 .KeyProperty(x => x.DepartmentNo, "DEPARTMENT_NO");

		Map(x => x.Description);
	}
}



public class WorkCenterMap : ClassMap<WorkCenter>
{
	public WorkCenterMap()
	{
		Table("WORK_CENTER");

		CompositeId().KeyProperty(x => x.Contract, "CONTRACT")
					 .KeyProperty(x => x.WorkCenterNo, "WORK_CENTER_NO");

		Map(x => x.Description);
		Map(x => x.QueueTime).Column("QUEUE_TIME");
		References(x => x.WorkCenterDepartment).Columns("CONTRACT", "DEPARTMENT_NO");
	}
}

public class WorkCenter
{
	public virtual Site Site { get; set; }
	public virtual string Contract { get; set; }
	public virtual string WorkCenterNo { get; set; }
	public virtual string Description { get; set; }
	public virtual string FullDescription
	{
		get
		{
			return $"{WorkCenterNo} - {Description}";
		}
	}
	public virtual double QueueTime { get; set; }
	public virtual WorkCenterDepartment WorkCenterDepartment { get; set; }
	public virtual ProductionLine ProductionLine { get; set; }
	public override bool Equals(object obj)
	{
		if (obj == null)
			return false;
		WorkCenter id;
		id = (WorkCenter)obj;
		if (id == null)
			return false;
		if (Contract == id.Contract && WorkCenterNo == id.WorkCenterNo)
			return true;
		return false;
	}
	public override int GetHashCode()
	{
		return (Contract + "|" + WorkCenterNo).GetHashCode();
	}
}

public class WorkCenterDepartment
{
	public virtual Site Site { get; set; }
	public virtual string DepartmentNo { get; set; }
	public virtual string Contract { get; set; }
	public virtual string Description { get; set; }
	public virtual string FullDescription
	{
		get
		{
			return $"{DepartmentNo} - {Description}";
		}
	}
	public override bool Equals(object obj)
	{
		if (obj == null)
			return false;
		WorkCenterDepartment id;
		id = (WorkCenterDepartment)obj;
		if (id == null)
			return false;
		if (Contract == id.Contract && DepartmentNo == id.DepartmentNo)
			return true;
		return false;
	}
	public override int GetHashCode()
	{
		return (Contract + "|" + DepartmentNo).GetHashCode();
	}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions