I am trying to write a query that returns randomly ordered results. I found this Linq Orderby random ThreadSafe post for use in ASP.NET , which gave me some basic tips on how to do this. But I get the following exception:
variable 'x' of type 'Accomodations.DAL.Model.Generated.Accomodation' referring to scope '' but not defined
Here is my request:
var query = session.QueryOver<Accomodation>() .OrderBy(x => (~(x.Id & seed)) & (x.Id | seed)).Asc; // this is the problematic line of code if (searchParams.District != 0) query = query.Where(x => x.District.Id == searchParams.District); if (searchParams.Region != 0) query = query.Where(x => x.Region.Id == searchParams.Region); if (searchParams.Location != 0) query = query.Where(x => x.Location.Id == searchParams.Location); var futureCount = query.Clone().Select(Projections.RowCount()).FutureValue<int>(); SearchAccomodationResultItem resultItemAlias = null; var futurePage = query .SelectList(list => list .Select(x => x.Id).WithAlias(() => resultItemAlias.Id) .Select(x => x.AccomodationType.Id).WithAlias(() => resultItemAlias.AccomodationTypeId) .Select(x => x.Region.Id).WithAlias(() => resultItemAlias.RegionId) .Select(x => x.Name).WithAlias(() => resultItemAlias.Title) .Select(x => x.MaxCapacity).WithAlias(() => resultItemAlias.MaxCapacity) .Select(x => x.MinPrice).WithAlias(() => resultItemAlias.MinPrice) .Select(x => x.MinStayLength).WithAlias(() => resultItemAlias.MinStayLength) .Select(x => x.MainImageName).WithAlias(() => resultItemAlias.ImgSrc) ) .TransformUsing(Transformers.AliasToBean<SearchAccomodationResultItem>()) .Skip(skip) .Take(searchParams.PageSize) .Future<SearchAccomodationResultItem>(); searchResults = futurePage.ToList(); numberOfResults = futureCount.Value; });
Any suggestion will be appreciated. Thanks
source share