0

I have 2 tables, Plan and Ticket. I want all the records that are in TravelPlan but not in Ticket.

    Template.Criteria.CreateCriteria("Plan")
              .Add(Subqueries.PropertyNotIn("UserID",
                                            DetachedCriteria.For(typeof(Ticket))
              .SetProjection(Projections.Property("UID")))); 

The above query doesnt return any records..

developer
  • 5,178
  • 11
  • 47
  • 72

1 Answers1

1

I can't guess what SearchTemplate does, but you are applying the projection to the outer criteria instead of the detached one.

Also, the "root" criteria should be for TravelPlan, not Ticket.

In other words:

criteria = DetachedCriteria.For<TravelPlan>()
               .Add(Subqueries.PropertyNotIn(
                        "UserId",
                        DetachedCriteria.For<Ticket>()
                            .SetProjection(Projections.Property("UID"))))

This assumes TravelPlan has a UserID property that is matches the UID property in Ticket.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154