我收到以下錯誤:功能NHibernate映射幫助
無效指數3本OracleParameterCollection以計數=當我試圖插入一個新列到表3
。
我的實體類是:
public class Operator
{
public Operator()
{
this.OperatorMemberships = new List<OperatorMembership>();
}
public virtual int Id { get; set; }
public virtual int OperatorMembershipId { get; set; }
public virtual int SchemeId { get; set; }
public virtual string Description { get; set; }
public virtual IList<OperatorMembership> OperatorMemberships { get; set; }
}
public class OperatorMembership
{
public virtual int Id { get; set; }
public virtual int OperatorId { get; set; } // delete
public virtual int UserRoleId { get; set; } // delete
public virtual UserRole UserRole { get; set; }
public virtual Operator Operator { get; set; }
}
我的映射是:
public OperatorMap()
{
Table("OPERATOR");
Id(x => x.Id, "OPERATOR_ID").GeneratedBy.Identity();
Map(x => x.SchemeId, "SCHEME_ID");
Map(x => x.Description, "DESCRIPTION");
//HasMany(x => x.OperatorMemberships).Inverse().AsBag().Cascade.AllDeleteOrphan();
HasMany(x => x.OperatorMemberships).Inverse().AsBag();
//References(x => x.SchemeServices, "OPERATOR_ID");
}
}
public class OperatorMembershipMap : ClassMap<OperatorMembership>
{
public OperatorMembershipMap()
{
Table("USER_OPERATOR_MEMBERSHIP");
Id(x => x.Id, "USER_OPERATOR_MEMBERSHIP_ID").GeneratedBy.Identity();
Map(x => x.OperatorId, "OPERATOR_ID");
Map(x => x.UserRoleId, "USER_ROLE_ID");
References(x => x.Operator).Column("OPERATOR_ID"); ;
References(x => x.UserRole).Column("USER_ROLE_ID");
}
}
代碼插入新行:
public int AddOperatorMembership(int operatorId, int userRoleId)
{
OperatorMembership op = new OperatorMembership();
op.OperatorId = operatorId;
op.UserRoleId = userRoleId;
_provider.AddEntity(op);
return op.Id;
}
和我的數據庫表:
USER_OPERATOR_MEMBERSHIP_ID -- OPERATOR_ID -- USER_ROLE_ID
任何幫助都很好,我確信有一些非常聰明流利的nhibernate開發人員可以馬上發現錯誤。
非常感謝。
Randolf。
如果刪除的屬性,然後我不能與我的代碼訪問它們用於與這些值的更新:op.OperatorId = operatorId; op.UserRoleId = userRoleId; – 2011-05-27 13:33:36
好的,但是你會在你的問題中出現錯誤。 – mathieu 2011-05-27 14:54:45
你可以使用op.Operator = session.Load(operatorId) – mathieu 2011-05-27 14:56:14