NHibernate的标准问题
我尝试使用NHibernate进行数据访问,我有两个简单的实体,如下所示:NHibernate的标准问题,nhibernate,criteria,Nhibernate,Criteria,我尝试使用NHibernate进行数据访问,我有两个简单的实体,如下所示: public class User : IEntity { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } public string Logon { get; set
public class User : IEntity
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Logon { get; set; }
public string Password { get; set; }
public ICollection<Role> Roles { get; set; }
public bool IsNew
{
get { return (ID == 0) ? true : false; }
}
public User()
{
Roles = new List<Role>();
}
}
public class Role : IEntity
{
public int ID { get; set; }
public string RoleName { get; set; }
public string RoleDescription { get; set; }
public bool IsNew
{
get { return (ID == 0) ? true : false; }
}
}
公共类用户:IEntity
{
公共int ID{get;set;}
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共字符串电子邮件{get;set;}
公共字符串登录{get;set;}
公共字符串密码{get;set;}
公共ICollection角色{get;set;}
公共图书馆是新的
{
获取{return(ID==0)?true:false;}
}
公共用户()
{
角色=新列表();
}
}
公共类角色:公共性
{
公共int ID{get;set;}
公共字符串RoleName{get;set;}
公共字符串角色描述{get;set;}
公共图书馆是新的
{
获取{return(ID==0)?true:false;}
}
}
我的问题……如果我想在其角色集合中找到任何包含ID为1的角色的用户,我该如何构造条件 没关系,这最终是相对直接的:
// role was the role passed in to my Find method.
var criteria = DetachedCriteria.For(typeof (User))
.CreateCriteria("Roles")
.Add(Restrictions.Eq("ID", role.ID));
对于类角色,为什么只有RoleName和Description而不是Name和Description?您还可以将IsNew填充到基类中。IEntity接口保留了什么?这是另一个问题,但你能问一下吗。我喜欢学习技巧