Nhibernate DetachedCriteria:查找属性的属性与值匹配的实体
我有以下两个类:
public class User
{
public virtual Guid Id { get; set; }
public virtual UserCredentials Credentials { get; set; }
// other stuff
protected User() { }
}
public class UserCredentials
{
public virtual Guid Id { get; set; }
public virtual string UserName { get; set; }
// other stuff
protected UserCredentials() { }
}
我想创建一个独立的标准来查找 Credentials.UserName = "someuser"
的所有用户,但我无法正确执行..我已尝试以下操作:
DetachedCriteria.For<User>().Add(Expression.Eq("Credentials.UserName", "someuser");
但我得到一个例外的说法
“无法解析属性: 凭证.用户名: DataLinkNord.Domain.User"
任何帮助将不胜感激..
I have two following classes:
public class User
{
public virtual Guid Id { get; set; }
public virtual UserCredentials Credentials { get; set; }
// other stuff
protected User() { }
}
public class UserCredentials
{
public virtual Guid Id { get; set; }
public virtual string UserName { get; set; }
// other stuff
protected UserCredentials() { }
}
I want to create a detached criteria that finds all users where Credentials.UserName = "someuser"
, but I cannot get it right.. I have tried the following:
DetachedCriteria.For<User>().Add(Expression.Eq("Credentials.UserName", "someuser");
but I get an exception saying
"could not resolve property:
Credentials.UserName of:
DataLinkNord.Domain.User"
Any help would be appreciated..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前就遇到过这个问题(虽然我是 Java 用户),但对我来说解决这个问题的方法是首先使用“addAlias()”调用...类似:
I've run into this issue before myself (although I'm a Java user), but the way around it for me was to use the "addAlias()" call first... something like: