Note that there are some explanatory texts on larger screens.

plurals
  1. PONhibernate join with select columns from both tables
    primarykey
    data
    text
    <p>Ok after several attempts I am stuck on this one!</p> <p>I am using NHibernate with QueryOver as below. I have a Product and ProductReview as</p> <pre><code>public class Product { .... public virtual IList&lt;ProductReview&gt; CustomerReviews {get;set;} .... } public class ProductReview { .... public virtual Product Product {get;set;} .... } </code></pre> <p>Mapping on Product side is </p> <pre><code>HasMany(x =&gt; x.CustomerReviews).KeyColumn("ProductId").Inverse().Cascade.None().LazyLoad(); </code></pre> <p>The Query is</p> <pre><code> Product px = null; ProductReview rev = null; var result = CurrentSession .QueryOver&lt;ProductReview&gt;() .Where(r =&gt; r.IsActive &amp;&amp; !r.IsDraft) .Select( Projections.Property&lt;ProductReview&gt;(r =&gt; r.Id).WithAlias(() =&gt; rev.Id), Projections.Property&lt;ProductReview&gt;(r =&gt; r.Title).WithAlias(() =&gt; rev.Title) ) .OrderBy(r =&gt; r.ReviewDate).Desc() .TransformUsing(Transformers.AliasToBean&lt;ProductReview&gt;()) .JoinAlias(r =&gt; r.Product, () =&gt; px) .Select( Projections.Property(() =&gt; px.UPC).WithAlias(() =&gt; px.UPC), Projections.Property(() =&gt; px.FullName).WithAlias(() =&gt; px.FullName) ) .TransformUsing(Transformers.AliasToBean&lt;Product&gt;()) .Take(5) .List(); </code></pre> <p>The error is: The value "Reviews.Models.Product" is not of type "Reviews.Models.ProductReview" and cannot be used in this generic collection. Parameter name: value</p> <p>I really do not want to create another DTO. I would like to get the list of Last 5 new reviews and have it's Product populated (only a few required fields on both entities should be filled).</p> <p>Is this possible by any means (except raw sql) in NHibernate 3.0?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload