我正在使用流利的NHibernate。我有一个名为审计的类,它具有ItemID属性。每次我想在那个表中保存任何东西时,请告诉我这个错误。
错误消息:在INSERT的SET子句或列列表中多次指定列名'itemid‘。在同一子句中,不能为列分配多个值。修改子句以确保只更新一次列。如果此语句更新或向视图中插入列,则列别名会隐藏代码中的重复。
类
public class Audit : EntityBase
{
/*********
** Accessors
*********/
/// <summary>When the action was logged.</summary>
public virtual DateTime Date { get; set; }
/// <summary>The person who triggered the action.</summary>
public virtual BasicUser User { get; set; }
/// <summary>The name of the related group, used for filtering (e.g. idea, system-settings, site-editor)</summary>
public virtual string ItemGroup { get; set; }
/// <summary>The ID of the related entity.</summary>
public virtual int ItemID { get; set; }
/// <summary>The title of the related entity.</summary>
public virtual LocalizableString ItemTitle { get; set; }
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
public Audit() { }
}映射:
public class AuditMapper<T> : IEntityMapper<T>
where T : Audit
{
public virtual void ExtendDomainModel(IEntityMetadata<T> metadata)
{
metadata.MapTablePerClassHierarchy<Audit, T>("`ItemGroup`");
if (!metadata.IsSubclass)
{
metadata.Map.ManyToOne(entity => entity.User, relation => relation.Column("`userid`"));
metadata.Map.Property(c => c.ItemGroup, mapper =>
{
mapper.Insert(false);
mapper.Update(false);
});
metadata.Map.Property(c => c.ItemID, mapper => mapper.Column("itemid"));
}
else
{
metadata.MapSubclass.ManyToOne(entity => entity.User, relation => relation.Column("`userid`"));
metadata.MapSubclass.Property(c => c.ItemGroup, mapper =>
{
mapper.Insert(false);
mapper.Update(false);
});
metadata.MapSubclass.Property(c => c.ItemID, mapper =>
{
mapper.Insert(false);
mapper.Update(false);
});
}
}
}SQL查询:
idealink.core.audit值(@p0,@p1,@p2,@p3,@p4,@p5,'IdeaAudit');选择SCOPE_IDENTITY()
发布于 2018-07-27 17:24:28
我在地图上解决了这个问题。
我改变了
metadata.Map.Property(c => c.ItemID, mapper => mapper.Column("itemid"));至
metadata.Map.Property(c => c.ItemID, mapper =>
{
mapper.Insert(false);
mapper.Update(false);
});https://stackoverflow.com/questions/51559014
复制相似问题