我正在使用Fluent NHibernate。我有一个名为Audit的类,它具有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查询:
插入[智囊团]。[理想链接.core.audit]([日期],[用户ID],项目ID,[项目标题_key],[项目名称_原始],[项ID],[条目组](值(@p0,@p1,@p2,@p3,@p4,@p5,'IdeaAudit'(;选择SCOPE_IDENTITY((
我在映射程序中修复了这个问题。
我更改了
metadata.Map.Property(c => c.ItemID, mapper => mapper.Column("itemid"));
至
metadata.Map.Property(c => c.ItemID, mapper =>
{
mapper.Insert(false);
mapper.Update(false);
});