Question: I have a user class:

```
public class User
{
   public virtual int ID {get;set;}
   public virtual string UserGuid {get;set;}  // its unique!
}

```

Can someone show me how to query using HQL and criteria to get the user by UserGuid?

Answer: 
Matthieu gave you the HQL here's the Criteria:

```
public User GetUserByUserGuid(Guid userGuid){

  ICriteria crit = Session.CreateCriteria<User>();
  crit.Add(Expression.Eq("UserGuid", userGuid));
  return crit.UniqueResult<User>(); //will return null if not found

}

```
if it's unique :

```
var query = Session.CreateQuery("from User u where u.UserGuid = :id");
            query.SetString("id", id);

var user = query.UniqueResult<User>();

```