SQL query with inner join to NHibernate with QueryOver

I have this SQL query :

select pr.*, det.Description, det.Name 
from Product pr 
inner join ProductDetail det on det.Product_id = pr.id
where pr.Id = XX and det.IsDefault = yy

How can I do this with QueryOver ?

Thanks,

Update :

public ProductMap()
{
    Id(x => x.Id).GeneratedBy.Native();
    Map(x => x.Code)
        .Length(20)
        .Not.Nullable();
    Map(x => x.CreationDate).Not.Nullable();
    Map(x => x.IsDeleted);
    Map(x => x.Price);
    HasManyToMany(x => x.Categories)
        .AsSet()
        .Cascade
        .SaveUpdate()
        .Table("ProductsCategories");
}

public class ProductDetailMap : ClassMap<ProductDetail>
{
    public ProductDetailMap()
    {
        Id(x => x.Id).GeneratedBy.Native();
        Map(x => x.Name)
            .Length(50)
            .Not.Nullable();
        Map(x => x.Description)
            .Length(250);
        Map(x => x.IsDefault);
        References(x => x.Language);
        References(x => x.Product);
    }
}

Answers


As far as I know QueryOver has no equivalent of the "pr.*" part, which would be nice. Which means you would have to manually specify each property of pr in your query.

See the section "Projections" on the document here

But it would be something like:

Product productAlias = null;
ProductDetail productDetail = null;
var query = session.QueryOver(() => productAlias)
                     .Inner.JoinAlias(() => productAlias.ProductDetails, () => productDetail)
                     .Where(() => productAlias.Id == XX && productDetail.IsDefault == YY)
                     .SelectList(list => list
                         .Select(() => productAlias.Id)
                         .Select(() => productAlias.Property1)
                         .Select(() => productAlias.Property2) 
                         // and so on...
                         .Select(() => productDetail.Description)
                         .Select(() => productDetail.Name)
                      );

// One way of doing it... 
// Will give you a list of object arrays matching the result
var results1 = query.List<object[]>();

// Another way...
// You need to define a class that has all the properties your are querying for
// If we create a class like that called "MySummaryClass" you can do:
var results2 = query.TransformUsing(Transformers.AliasToBean<MySummaryClass>()).List<MySummaryClass>();

Need Your Help

Some problems to inconify a JFrame window when the user click on the X button in this specific case, some ideas?

java swing events jframe actionlistener

I have the following problem: I am working on a Java Swing application that show me a JFrame. What I have to do is that when the user click on the X button the window have to be iconified and not c...

WebDriver wait for iframe, identify by part of its name

java iframe selenium selenium-webdriver

I have a problem on waiting for an iframe and switching to it when I know only part of its name. The name is unique every time the page is loaded. The pattern is "Framexxxxxxx" where "xxxxx" are ra...