Accepted answer

You cannot use another entity property like that. NHibernate expects expression that can be evaluated to property of the current entity. You need to use JoinQueryOver or JoinAlias to join another entity, and perform where after that.

With JoinQueryOver:

// ...
query = query.JoinQueryOver(x => x.Equipment)
    .JoinQueryOver(x => x.Company)
    .Where(c => c.Id == idCompany.Value);

With JoinAlias:

Equipment equipment = null;
Company company = null;

// ...
query = query.JoinAlias(x => x.Equipment, () => equipment)
    .JoinAlias(() => equipment.Company, () => company)
    .Where(() => company.Id == idCompany.Value);

Some more info:
What is the difference between JoinQueryOver and JoinAlias?
What can be used as a NHibernate QueryOver alias?
Complex nHibernate QueryOver expression


The tags chosen for your question make me think you didn't want to use QueryOver, but LINQ.

This is achieved by using the extension method Query, in the NHibernate.Linq namespace:

var query = session.Query<Laudo>().Fetch(x => x.Equipament);
if (idEquipament.HasValue) 
  query = query.Where(x => x.Equipament.Id == idEquipament.Value);
if (idCompany.HasValue)
  query = query.Where(x => x.Equipament.Company.Id == idCompany.Value);

Related Articles