KoteswaraRao Ankalla
unread,Apr 25, 2012, 4:19:11 AM4/25/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ravendb
Hi All,
We observed some issues with orderby in raven db, when we are trying
to get results using different sort conditions using the below code:
Here is the Method to get all Projects/documents in given sort order.
public static List<CommunityProject> GetAllProjects(string sortBy)
{
using (var documentSession = Instance.OpenSession())
{
var linqQuery = documentSession.Query<CommunityProject,
ProjectListIndex>();
switch (sortBy)
{
case "recent":
linqQuery = query.OrderByDescending(x => x.CreationDateUtc);
case "view":
linqQuery = query.OrderByDescending(x => x.NumberOfViews);
case "photo":
linqQuery = query.OrderByDescending(x => x.PrjImages.Count);
case "alpha":
linqQuery = query.OrderBy(x => x.Name);
default:
linqQuery = query.OrderByDescending(x => x.CreationDateUtc);
}
return linqQuery.ToList();
}
}
Here is the Index:
public class ProjectListIndex :
AbstractIndexCreationTask<CommunityProject>
{
public ProjectListIndex()
{
Map = docs => from doc in docs
select new
{
PrjType =
doc.PrjType.Select(x => x),
IsEditorial =
doc.IsEditorial,
PrjLocation_City =
doc.PrjLocation.City,
PrjLocation_StateCode =
doc.PrjLocation.StateCode,
PrjLocation_State =
doc.PrjLocation.State,
PrjLocation_CountryCode =
doc.PrjLocation.CountryCode,
FirmName = doc.FirmName,
PrincipalInCharge =
doc.PrincipalInCharge,
Client = doc.Client,
IsActivePrj =
doc.IsActivePrj,
PrjDetail_Status =
doc.PrjDetail.Status,
PrjDetail_YearCompleted =
doc.PrjDetail.YearCompleted,
PrjDetail_Budget = (decimal)
doc.PrjDetail.Budget,
PrjDetail_PrjSize_Size =
doc.PrjDetail.PrjSize.Size,
PrjDetail_GreenCertifications
=
doc.PrjDetail.GreenCertifications.Select(x => x),
PrjDetail_AwardsWon_Title =
doc.PrjDetail.AwardsWon.Select(award =>
award.Title),
PrjDetail_Tags =
doc.PrjDetail.Tags.Select(x => x),
CreationDateUtc =
doc.CreationDateUtc,
NumberOfViews =
doc.NumberOfViews,
PrjImages_Count =
doc.PrjImages.Count,
UserName = doc.UserName,
Name = doc.Name,
Query = new object[]
{
doc.Name,
doc.Description,
doc.PrincipalInCharge,
doc.FirmName,
doc.UserName,
doc.PrjLocation.Country,
doc.PrjLocation.CountryCode,
doc.PrjLocation.City,
doc.PrjLocation.State,
doc.PrjLocation.StateCode,
doc.PrjDetail.Status,
doc.PrjType.Select(x => x),
doc.PrjProducts.Select(x => x.Name),
doc.PrjImages.Select(x => x.ImgDescription),
doc.PrjImages.Select(x => x.ImgName),
doc.PrjProducts.Select(x => x.Manufacturer),
doc.PrjDetail.AwardsWon.Select(award => award.Title),
doc.PrjDetail.GreenCertifications.Select(x => x),
doc.PrjDetail.Tags.Select(x => x)
}
};
}
}
The issue is :
Raven is not returning results in specified order, for example when we
query for project docs which contains most images first, it is not
returning results in correct order and not sure which order it is
following.
It is also not working for NumberOfViews.
For rest of the above cases(CreationDateUtc, Name) it is working fine
Please let us know, if you have any ideas to resolve our issues.
Thanks,
Koti.