Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.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-queryover-如何对连接的查询进行动态排序_C#_Nhibernate_Fluent Nhibernate_Queryover - Fatal编程技术网

C# nhibernate-queryover-如何对连接的查询进行动态排序

C# nhibernate-queryover-如何对连接的查询进行动态排序,c#,nhibernate,fluent-nhibernate,queryover,C#,Nhibernate,Fluent Nhibernate,Queryover,我在管理面板中有一个用户帐户表,该表保存来自不同db表(SQL数据库中的表)的数据。用户帐户表必须支持分页和排序。当我尝试使用从Account db表中获取的“FirstName”对数据进行排序时,.net抛出一个异常,表示Location db表没有“FirstName”列。我的方法是: Account acc = null; //bunu bu şekilde tanımlamadan olmuyor :S AccountLogin accl = null;

我在管理面板中有一个用户帐户表,该表保存来自不同db表(SQL数据库中的表)的数据。用户帐户表必须支持分页和排序。当我尝试使用从Account db表中获取的“FirstName”对数据进行排序时,.net抛出一个异常,表示Location db表没有“FirstName”列。我的方法是:

        Account acc = null; //bunu bu şekilde tanımlamadan olmuyor :S
        AccountLogin accl = null; //bunu bu şekilde tanımlamadan olmuyor :S
        Program prog = null;
        Location school = null;
        Location town = null;
        Location city = null;

        //Takip edilen bloggerın tüm blog sayfalarını çek
        var query = Session.QueryOver<Account>(() => acc)
            .Left.JoinQueryOver<AccountLogin>(x => x.Logins, () => accl)
            .Left.JoinQueryOver(x => acc.AtentedToProgram, () => prog)
            .Left.JoinQueryOver(x => acc.LiveIn, () => school)
            .Left.JoinQueryOver(x => school.Parent, () => town)
            .Left.JoinQueryOver(x => town.Parent, () => city)
            .Where(x =>                                   acc.CreateDate.IsBetween(DateTime.Now.AddMonths(-12)).And(DateTime.Now)
                   );

        if (program_id != 0)
            query.And(x => prog.program_id == program_id);

        search = search??"";

        string[] searchedTags = search.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        if (searchedTags != null && searchedTags.Count() > 0)
        {
            Disjunction dis = new Disjunction();

            for (int i = 0; i < searchedTags.Count(); i++)
            {
                dis.Add(Expression.Like(Projections.Property(() => accl.UserName), searchedTags[i], MatchMode.Anywhere));
                dis.Add(Expression.Like(Projections.Property(() => acc.FirstName), searchedTags[i], MatchMode.Anywhere));
                dis.Add(Expression.Like(Projections.Property(() => acc.LastName), searchedTags[i], MatchMode.Anywhere));
                dis.Add(Expression.Like(Projections.Property(() => acc.Email), searchedTags[i], MatchMode.Anywhere));
            }

            query.And(dis);
        }

        if (city_id != 0)
            query.And(x => city.LocationId == city_id);

        if (town_id != 0)
            query.And(x => town.LocationId == town_id);

        if (school_id != 0)
            query.And(x => school.LocationId == school_id);

        var countquery = query.Clone().ToRowCountQuery().FutureValue<int>();

        pager.TotalPageNumber = countquery.Value;

         //acc.GetType().GetProperty(pager.SortColumn)
        var orderred = query.OrderBy(Projections.Property(pager.SortColumn));



            return ordered.Skip(pager.Skip).Take(pager.Take).List();
ack acc=null//布努布伊基尔德·坦姆拉马丹·奥尔穆约尔:S
AccountLogin accl=null//布努布伊基尔德·坦姆拉马丹·奥尔穆约尔:S
程序prog=null;
地点学校=空;
地点=空;
地点城市=空;
//Takip edilen博客作者ın Tum博客sayfalarınıçek
var query=Session.QueryOver(()=>acc)
.Left.JoinQueryOver(x=>x.Logins,()=>accl)
.Left.JoinQueryOver(x=>acc.atedtoprogram,()=>prog)
.Left.JoinQueryOver(x=>acc.LiveIn,()=>school)
.Left.JoinQueryOver(x=>学校.家长,()=>城镇)
.Left.JoinQueryOver(x=>town.Parent,()=>city)
其中(x=>acc.CreateDate.IsBetween(DateTime.Now.AddMonths(-12))和(DateTime.Now)
);
如果(程序id!=0)
And(x=>prog.program\u id==program\u id);
搜索=搜索;
string[]searchedTags=search.Split(新[]{''},StringSplitOptions.RemoveEmptyEntries);
if(searchedTags!=null&&searchedTags.Count()>0)
{
析取dis=新析取();
对于(int i=0;iaccl.UserName),searchedTags[i],MatchMode.Anywhere));
dis.Add(Expression.Like(Projections.Property(()=>acc.FirstName),searchedTags[i],MatchMode.Anywhere));
dis.Add(Expression.Like(Projections.Property(()=>acc.LastName),searchedTags[i],MatchMode.Anywhere));
dis.Add(Expression.Like(Projections.Property(()=>acc.Email),searchedTags[i],MatchMode.Anywhere));
}
查询.及(dis);
}
如果(城市id!=0)
和(x=>city.LocationId==city\u id);
如果(城镇id!=0)
和(x=>town.LocationId==town\u id);
如果(学校id!=0)
和(x=>school.LocationId==school\u id);
var countquery=query.Clone().ToRowCountQuery().FutureValue();
pager.TotalPageNumber=countquery.Value;
//acc.GetType().GetProperty(pager.SortColumn)
var orderred=query.OrderBy(Projections.Property(pager.SortColumn));
返回ordered.Skip(pager.Skip).Take(pager.Take).List();
var orderred=query.OrderBy(Projections.Property(pager.SortColumn));线路有问题


问题是,当我将pager.SortColumn参数作为字符串传递给OrderBy方法时,它无法知道哪个表具有该列,并尝试从上次加入db表的位置db表中获取“Firstname”。我怎样才能解决这个问题?提前感谢

您使用的是
JoinQueryOver
,但以后不要在lambdas中使用x。您可能打算
JoinAlias
创建别名

.Left.JoinAlias<AccountLogin>(x => x.Logins, () => accl)
.Left.JoinAlias(() => acc.AtentedToProgram, () => prog)
.Left.JoinAlias(() => acc.LiveIn, () => school)
.Left.JoinAlias(() => school.Parent, () => town)
.Left.JoinAlias(() => town.Parent, () => city)
.Left.JoinAlias(x=>x.Logins,()=>accl)
.Left.JoinAlias(()=>acc.AtentedToProgram,()=>prog)
.Left.JoinAlias(()=>acc.LiveIn,()=>school)
.Left.JoinAlias(()=>学校.家长,()=>城镇)
.Left.JoinAlias(()=>town.Parent,()=>city)

它保存页面索引、页面大小、排序列等分页和排序数据。用于将数据传递给方法。