I have 2 tables, I'd like place some fields in a result class, but I'm 
stuck. The code I want look like this with Entity Framework :

var res =   
(from p in context.EstimationItem
    join q in ...
    select new EstimationWithDetail
    {
        Estimation = q.Estimation,
        Id = q.Id,
        FullName = q.Customer.FirstName + q.Customer.LastName

    }).ToList();

In Nibernate, at this time, I have this, but I'm stuck ...

var res =
    Session.QueryOver<EstimationItem>()
    .JoinQueryOver(x => x.Estimation)
    .Select(
        x => x.Estimation.Reference,
        x => x.Estimation.CreationDate,
        x => x.Price,
        x => x.Estimation.Customer.FirstName,
        x => x.Estimation.Customer.LastName
        )
    .List();

public class Estimation
{
    public virtual string Reference { get; set; }
    public virtual Customer Customer { get; set; }
    public virtual DateTime CreationDate { get; set; }
    public virtual decimal Total { get; set; }
    public virtual IList<EstimationItem> EstimationItems { get; set; }
}

public class EstimationItem
{
    public virtual decimal Price { get; set; }
    public virtual int Quantity { get; set; }
    public virtual Estimation Estimation { get; set; }
    public virtual Product Product { get; set; }
}

public class EstimationWithDetail
{
    public string Reference { get; set; }       //Estimation.Reference
    public string FullName { get; set; }        //concat FirstName and LastName 
from Customer
    public decimal Price { get; set; }          //Estimation.Total
    public int Id { get; set; }                 //Estimation.Id
    public DateTime CreationDate { get; set; }  //Estimation.CreationDate
}

*
*

*I thirs this too :*

I tried the code but I get this error : *InvalidOperarionException, 
variable 'x' of type 'EstimationItem' referenced from scope '', but it is 
not defined*

var res =
    Session.QueryOver<EstimationItem>()
    .JoinQueryOver(x => x.Estimation)
    .Select(x => new EstimationWithDetail
    {
        Code = x.Estimation.Reference,
        CreationDate = x.Estimation.CreationDate,
        Price = x.Estimation.Total,
        FullName = x.Estimation.Customer.FirstName + 
x.Estimation.Customer.LastName
    })
    .List<EstimationWithDetail>();

*
*

*And thid*

Estimation a = null;
Customer b = null;
var res = Session.QueryOver<EstimationItem>()
    .JoinAlias(c => c.Estimation, () => a)
    .JoinAlias(c => c.Estimation.Customer, () => b)
    .Select(x => new EstimationWithDetail
    {
        Code = a.Reference,
        Id = a.Id,
        FullName = b.LastName
    })
    .List<EstimationWithDetail>();

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/TYiDOZ-3iO4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to