我有一个像这样的POCO:
public class UserLogin
{
public virtual string LoginProvider { get; set; }
public virtual string ProviderKey { get; set; }
public virtual User User { get; set; }
public virtual bool Deleted { get; set; }
public override bool Equals(object obj)
{
var t = obj as UserLogin;
if (t == null)
return false;
return LoginProvider == t.ProviderKey && User.UserId == t.User.UserId;
}
public override int GetHashCode()
{
return (LoginProvider + "|" + ProviderKey + "|" + User.UserId).GetHashCode();
}
映射如下:
public class UserLoginMap : ClassMap<UserLogin>
{
public UserLoginMap()
{
CompositeId()
.KeyProperty(x => x.LoginProvider)
.KeyProperty(x => x.ProviderKey)
.KeyReference(x => x.User, "UserId");
}
}
现在我如何根据它的关键值通过Nhibernation会话删除其中一个实体,而不承担在代码中放入SQL字符串的主要罪行?
答案 0 :(得分:0)
*没有看到工作,这里有未来的参考! * 强>
未经测试,但取自https://stackoverflow.com/a/4829372/613130(回复适用于Session.Get
,但我确实希望它对Session.Delete
起作用,甚至还有评论{{1} })
使用ids创建“假”对象树:
This even works with composite IDs that include referenced classes