0

I'm using linq in nhibernate and I have problem when I try to use OrderBy using Dynamic Linq:

        var bugAndFeatures = (from u in session.Query<BugAndFeature>()
                              let uEmployeeFullName = string.Format("{0} {1}", u.Employee.Surname, u.Employee.FirstName)
                              where u.IsDelete == false
                              select new BugAndFeatureView()
                              {
                                  Id = u.Id,
                                  Title = u.Title,
                                  Description = u.Description,
                                  EmployeeFullName = uEmployeeFullName,
                                  EmployeeLogin = u.Employee.User.Login,
                                  AssignedEmployeeId = u.AssignedEmployee == null ? 0 : u.AssignedEmployee.Id,
                                  AssignedEmployeeFullName = string.Format("{0} {1}", u.AssignedEmployee.Surname, u.AssignedEmployee.FirstName),
                                  CreateDate = u.CreateDate.Equals(null) ? string.Empty : u.CreateDate.ToString(),
                                  LastUpdateDate = u.LastUpdateDate.Equals(null) ? string.Empty : u.LastUpdateDate.ToString()
                              }
                     );

After that I would like to use dynamic linq and use OrderBy like OrderBy("EmployeeFullName DESC") and I couldn't do that because I have exception. I noticed that when I'm doing OrderBy on any property which I don't format or check null etc. I don't have this problem it only occurs when I try to do orderby with formated properties. If I do ToList() before OrderBy then I don't have this problem but I don't want to do that I need use IQueryable.

How can I modify this query to solve my issue?

Thanks for help.

hashiQ
  • 1

1 Answers1

0

Have you try like this:

var Results = bugAndFeatures.ToList().OrderBy(p => p.EmployeeFullName);

 IQueryable<Foo> query = ...;

 switch (orderByParameter)
                {
                    case "SomeValueParamter":
                        query = query.OrderBy(x => x.SomeValueParamter);
                        break;
                    case "SomeValueParamter":
                        query = query.OrderBy(x => x.SomeValueParamter);
                        break;
                    // etc
                }
Nayeem Mansoori
  • 1
  • 1
  • 13
  • 39
  • I don't want to do ToList At this step I need IQueryable and also I need use dynamic linq. – hashiQ Apr 18 '14 at 09:59
  • I tried to use extension method without using dynamic linq but I still have the same problem - I think that calculated properties doing this problem (as I mentioned when I'm using OrderBy using extension method or dynamic linq I have the same problem with properties that I formating, checking something or calculating) – hashiQ Apr 18 '14 at 10:22