Try fast search NHibernate

29 June 2009

NHibernate3 Criteria

When you work in an Open Source project, in how many hours a blog post, about a limitation, can become obsolete ?

This

var criteria = session.CreateCriteria(typeof(Person))
.Add(Restrictions
.And(Restrictions.Eq("Name", "Richard"),
Restrictions.Or(Restrictions.Gt("Age", 21),
Restrictions.Eq("HasCar", true))));

in NH3.0.0 will look

var query = session.QueryOver<Person>()
.Where(p => p.Name == "Richard" && (p.Age > 21 || p.HasCar));

well… the answer to the above question is : in few hours.

Thanks Richard.

P.S. perhaps now I can reconsider my opinion about Criteria readability.

12 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. It sounds as the same as http://code.google.com/p/nhlambdaextensions/

    ReplyDelete
  3. @cprieto
    did you read the linked previous post ?
    Richard Brown is the nhlambdaextensions project leader and now he is a NH-Core committer.
    In practice nhlambdaextensions will be full imported and improved in NH3.0.0.

    ReplyDelete
  4. yeah, thats fast progress ;)
    when nh3.0.0 will get released we have the option of lambda criterias and nhibernate to linq, right? under wich circumstances would one chose which option?

    ReplyDelete
  5. I don't know exactly which options we will release in NH3.0.0; for sure you will have more than two to query your domain.

    ReplyDelete
  6. How would an ICriteria with multiple level or statements look like?

    That is, given this HQL:
    from Company c
    left join c.Manager manager
    where c.Name like 'Oracle' or manager.Name like 'Tomas'

    How will it look like?

    ReplyDelete
  7. @Darius
    We are working on it; Richard more than me (so far I'm helping him only by talking).
    About "substitution" : even linq2nh will have some problem to substitute HQL at all. HQL is not so general purpose, HQL was thought to have a powerful query language to query entities-domain.

    ReplyDelete
  8. Deam!, NH is being updated faster than I can absorbe the news. You're giving us too much new things to play with.
    Thanks Fabio and all the team for these improvements!

    ReplyDelete
  9. @Diego
    For sure, you will the one known from where come some QueryOver syntax... a pending work is becoming a reality in NH-Core.

    ReplyDelete
  10. Thanks Fabio for answer.
    Today i will be giving a short presentation on NHibernate in Lithuanian .Net user group meeting, so i will spread the good news ;)

    ReplyDelete
  11. @Fabio
    Cool, I really love the work in NHLambda, great to see it included in NHibernate Core now :D

    ReplyDelete