gpt4 book ai didi

c# - NHibernate.查询异常 : could not resolve property - Column name with ID

转载 作者:太空狗 更新时间:2023-10-30 00:54:54 25 4
gpt4 key购买 nike

当我尝试使用 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));
}

上课

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;
}

}

有映射,

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();
}

它抛出异常,

NHibernate.QueryException: could not resolve property: UserGroupID

如何解决属性(property)问题?

最佳答案

不要在查询中指定列名,而是尝试使用类的属性标识符(末尾为小写字母):

return session.CreateCriteria(typeof(UserUserGroup))
.Add(Restrictions.Eq("UserGroupId", _userGroupId))
.Add(Restrictions.Eq("UserId", _userId))
.Add(Restrictions.Eq("Deleted", false))
.List();

为避免将来出现此类问题,我建议您使用 QueryOver API ,它在编译时提供类型检查:

return session.QueryOver<UserUserGroup>()
.Where(x => x.UserGroupId == _userGroupId)
.And(x => x.UserId == _userId)
.And(x => x.Deleted == false)
.List();

关于c# - NHibernate.查询异常 : could not resolve property - Column name with ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11198526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com