When I try to execute the below class using ICriteria,
if (_userGroupId > 0 && _userId > 0 )
{
return session.CreateCriteria(typeof(UserUserGroup))
.Add(Restrictions.Eq("UserGroupID", _userGroupId))
.Add(Restrictions.Eq("UserID", _userId))
.Add(Restrictions.Eq("Deleted", false));
}
for class
public class UserUserGroup
{
public virtual long UserUserGroupId { get; set; }
public virtual long UserGroupId { get; set; }
public virtual long UserId { get; set; }
public virtual bool Deleted { get; set; }
public UserUserGroup() {}
public UserUserGroup(long userGroupId, long userId)
{
UserGroupId = userGroupId;
UserId = userId;
}
}
with Mapping,
public void Override(AutoMapping<UserUserGroup> mapping)
{
mapping.Id(map => map.UserUserGroupId, "UserUserGroupID").GeneratedBy.HiLo("hibernate_unique_key", "next_hi", "100", "tablename='UserUserGroups'");
mapping.Map(map => map.UserId,"UserID").Nullable();
mapping.Map(map => map.UserGroupId,"UserGroupID").Nullable();
mapping.Map(map => map.Deleted,"Deleted").Nullable();
}
It throws Exception,
NHibernate.QueryException: could not resolve property: UserGroupID
How to get the property resolved?
Instead of specifying column names in your query, try using your class’s properties identifiers (lower case letters at the end):
To avoid this kind of problem in the future, I suggest you use the QueryOver API, which provides type checking at compilation time: