0

How can I add a projection to this code? I am trying to sort my results according to date created or last updated.

    var c = new Conjunction();
    c.Add(Restrictions.Where<InstructionTask>(x => x.IsOpen == _setDefaultStatusIfNotFound(status)));

//error adding this projection:

    if (string.IsNullOrEmpty(sort) || sort.Equals("created", StringComparison.OrdinalIgnoreCase))
        c.Add(Projections.Property<InstructionTask>(x => x.DateCreated));

I am passing in my Conjuction to another method that will handle the retrieving of tasks i.e. var tasks = GetCollaboratedTasks(c);

Haroon
  • 3,402
  • 6
  • 43
  • 74

2 Answers2

0

A conjuction is just a group of filters that will be ANDed together. It is not related to projection or sorting. You need to stick it in a DetachedCriteria or ICriteria.

Oskar Berggren
  • 5,583
  • 1
  • 19
  • 36
0

To sort your results by the property DateCreated use:

criteria.AddOrder(Order.Asc(Projections.Property<InstructionTask>(x => x.DateCreated));

As Oskar said, a Conjunction can only be used to apply filters.

csanchez
  • 121
  • 3