当我调用“ task.Assignee.Clear() ”时,nhibernate 在 SQLLite 和 SQLServer 的 SQL 下创建(调用时在 Assignee 中的一条记录)
DELETE FROM TaskAssignees
WHERE TaskId = 'd8e13c83-20b8-4ce6-a814-a264000c21a6' /* @p0 */
AND UserId = 'f676b54b-d986-4659-a4aa-9103d928f91b' /* @p1 */
AND TeamId = NULL /* @p2 */
AND DepartmentId = NULL /* @p3 */
AND VirtualUserId = NULL /* @p4 */
AND IsMain = 1
这个查询没有执行,因为=NULL是对sql的错误检查,一定是这样的
DELETE FROM TaskAssignees
WHERE TaskId = 'd8e13c83-20b8-4ce6-a814-a264000c21a6' /* @p0 */
AND UserId = 'f676b54b-d986-4659-a4aa-9103d928f91b' /* @p1 */
AND TeamId is NULL /* @p2 */
AND DepartmentId is NULL /* @p3 */
AND VirtualUserId is NULL /* @p4 */
AND IsMain = 1
我该如何解决这个问题?
我使用 FluentNhibernate 进行映射,并使用 NHibernate 3.3
映射和类:
public TaskMap()
{
Table("Tasks");
CompositeId<TaskId>(x => x.Id).KeyProperty(t => t.Id);
Map(x => x.Name).Not.Nullable();
HasMany(x => x.Assignees)
.AsList(c => c.Column("AssigneeIndex"))
.Component(m =>
{
m.Component(x => x.UserId, mm => mm.Map(x => x.Id).Column("UserId").Nullable());
m.Component(x => x.TeamId, mm => mm.Map(x => x.Id).Column("TeamId").Nullable());
m.Component(x => x.DepartmentId, mm => mm.Map(x => x.Id).Column("DepartmentId").Nullable());
m.Component(x => x.VirtualUserId, mm => mm.Map(x => x.Id).Column("VirtualUserId").Nullable());
m.Map(x => x.IsMain).Not.Nullable();
})
.KeyColumn("TaskId")
.Table("TaskAssignees")
.Cascade.All();
}
public class Task : Entity<TaskId>
{
public TaskId Id {get;set;}
public string Name {get;set;}
public Iesi.Collections.Generic.ISet<TaskAssignee> Assignees {get;set;}
}
public class TaskAssignee : ValueObject
{
public UserId UserId {get;protected set;}
public TeamId TeamId {get;protected set;}
public VirtualUserId VirtualUserId {get;protected set;}
public DepartmentId DepartmentId {get;protected set;}
public bool IsMain {get;protected set;}
}
public class TaskId : ValueObject
{
public Guid Id {get;protected set;}
}
public class TeamId : ValueObject
{
public Guid Id {get;protected set;}
}
public class VirtualUserId : ValueObject
{
public Guid Id {get;protected set;}
}
public class DepartmentId : ValueObject
{
public Guid Id {get;protected set;}
}
public class UserId : ValueObject
{
public Guid Id {get;protected set;}
}