我有一个用户帐户表管理面板,这台拥有不同的数据库表(在SQL数据库表)的数据。 和用户帐户表必须支持分页和排序。 当我尝试将数据与“姓”从帐户数据库表取回排序,.NET抛出一个异常,说位置数据库表中没有“姓”列。 我的方法是这样的:
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();
VAR orderred = query.OrderBy(Projections.Property(pager.SortColumn)); 线路有问题。
这个问题,当我通过pager.SortColumn参数作为字符串的OrderBy方法,它不能知道哪个表有列,并尝试从最后被加入数据库表位置db表得到“名字”。 我该如何解决这个问题? 提前致谢