Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我想不出我是什么';我在这个基本的NHibernate查询中出错了_C#_Nhibernate_Sqlite_Fluent Nhibernate - Fatal编程技术网

C# 我想不出我是什么';我在这个基本的NHibernate查询中出错了

C# 我想不出我是什么';我在这个基本的NHibernate查询中出错了,c#,nhibernate,sqlite,fluent-nhibernate,C#,Nhibernate,Sqlite,Fluent Nhibernate,好的,我有一门课,Company public class Company { public virtual int Id { get; set; } public virtual IList<Role> Roles { get; set; } } 我用的是流畅的自动地图,没什么特别的 我有这个方法: private RoleLevel GetRole(int companyId) { var allRoles = Session.CreateCriteri

好的,我有一门课,
Company

public class Company
{
    public virtual int Id { get; set; }
    public virtual IList<Role> Roles { get; set; }
}
我用的是流畅的自动地图,没什么特别的

我有这个方法:

private RoleLevel GetRole(int companyId)
{
    var allRoles = Session.CreateCriteria<Role>().List<Role>();

    var role = Session.CreateCriteria<Role>()
        .CreateAlias(NameOf<Role>.Property(r => r.Company), "c")
        .Add(Restrictions.Eq("c.Id", companyId))
        .UniqueResult<Role>();

    return (role == null) ? RoleLevel.Restricted : role.RoleLevel;
}
编辑2


我尝试将数据库更改为SQL Server。在SQL Server中,这一切都可以正常工作。我猜这是NHibernate如何连接到SQLite数据库的一个bug?目前,我可以使用SQL Server DB进行测试,但出于速度原因,我希望将来使用内存中的SQLite DB。

首先,您是否对数据库运行了查询

第二,如果映射有问题,您是否可以尝试其他CreateCriteria?然后,您可以指定jointype,如下所示。只是为了确保我们在继续前进之前已经尝试了所有的基础知识:)

private RoleLevel GetRole(int companyId)
{
var allRoles=Session.CreateCriteria().List();
var role=Session.CreateCriteria(“r”)
.CreateCriteria(“公司”、“c”、JoinType.LeftOuterJoin)
.Add(限制条件Eq(“c.Id”,公司Id))
.UniqueResult();
返回(role==null)?RoleLevel.Restricted:role.RoleLevel;
}

第三,潜在的问题可能是表名周围有双引号。这表明存在映射问题。表名大小写不匹配或类似情况。

首先,您是否对数据库运行了查询

第二,如果映射有问题,您是否可以尝试其他CreateCriteria?然后,您可以指定jointype,如下所示。只是为了确保我们在继续前进之前已经尝试了所有的基础知识:)

private RoleLevel GetRole(int companyId)
{
var allRoles=Session.CreateCriteria().List();
var role=Session.CreateCriteria(“r”)
.CreateCriteria(“公司”、“c”、JoinType.LeftOuterJoin)
.Add(限制条件Eq(“c.Id”,公司Id))
.UniqueResult();
返回(role==null)?RoleLevel.Restricted:role.RoleLevel;
}

第三,潜在的问题可能是表名周围有双引号。这表明存在映射问题。表名大小写不匹配或类似情况。

您使用的是SQL Server吗?如果是,请尝试在服务器上运行跟踪并查看查询。它可能会帮助你检测你是否做错了什么。这是在测试中,所以它使用SQLite。我将把正在执行的查询添加到我的问题中。NHProf应该在底部有一个选项--“查看此查询产生的n行。”是否有任何结果?(您必须在NHProf中配置连接才能使用此功能。)它显示0行。抱歉,本应包含此内容。您使用的是SQL Server吗?如果是,请尝试在服务器上运行跟踪并查看查询。它可能会帮助你检测你是否做错了什么。这是在测试中,所以它使用SQLite。我将把正在执行的查询添加到我的问题中。NHProf应该在底部有一个选项--“查看此查询产生的n行。”是否有任何结果?(您必须在NHProf中配置连接才能使用此功能。)它显示0行。对不起,我的意思是包括这个。
private RoleLevel GetRole(int companyId)
{
    var allRoles = Session.CreateCriteria<Role>().List<Role>();

    var role = Session.CreateCriteria<Role>()
        .CreateAlias(NameOf<Role>.Property(r => r.Company), "c")
        .Add(Restrictions.Eq("c.Id", companyId))
        .UniqueResult<Role>();

    return (role == null) ? RoleLevel.Restricted : role.RoleLevel;
}
SELECT this_.Id         as Id75_1_,
       this_.Version    as Version75_1_,
       this_.RoleLevel  as RoleLevel75_1_,
       this_.DbDate     as DbDate75_1_,
       this_.Account_id as Account5_75_1_,
       this_.Company_id as Company6_75_1_,
       c1_.Id           as Id71_0_,
       c1_.Version      as Version71_0_,
       c1_.Name         as Name71_0_,
       c1_.OnyxAlias    as OnyxAlias71_0_,
       c1_.DbDate       as DbDate71_0_,
       c1_.Parent_Id    as Parent6_71_0_
FROM   "Role" this_
       inner join "Company" c1_
         on this_.Company_id = c1_.Id
WHERE  c1_.Id = 102 /* @p0 */
private RoleLevel GetRole(int companyId)
{
    var allRoles = Session.CreateCriteria<Role>().List<Role>();

    var role = Session.CreateCriteria<Role>("r")
        .CreateCriteria("Company", "c", JoinType.LeftOuterJoin)
        .Add(Restrictions.Eq("c.Id", companyId))
        .UniqueResult<Role>();

    return (role == null) ? RoleLevel.Restricted : role.RoleLevel;
}