Hello!

As the title says, is it possible to project an entity into a composite DTO?

// Entities
public class Person {
    public virtual int Id { get; set; }

    public virtual string Name { get; set; }

    public virtual Adress Address { get; set; }
}

public class Address {
    public virtual int Id { get; set; }

    public virtual string Street { get; set; }

    public virtual int Number { get; set; }
}

// DTOs
public class Dto {
    public int Id { get;set; }

    public string Name { get; set; }

    public AddressDto Address { get; set; }
}

public class AddressDto {
    public int Id { get; set; }

    public string Street { get; set; }

    public int Number { get; set; }
}

// The query
Dto dto = null;
Address address = null;
var q = session.QueryOver<Person>()
    .JoinAlias(i => i.Address, () => address)
    .SelectList(i => i
        .Select(j => j.Id).WithAlias(() => dto.Id)
        .Select(j => j.Name).WithAlias(() => dto.Name)
        .Select(j => address.Street).WithAlias(() => dto.Address.Street)
        .Select(j => address.Id).WithAlias() => dto.Address.Id)
        .Select(j => address.Number).WithAlias(() => dto.Address.Number)
    )
    .TransformUsing(Transformers.AliasToBean<Dto>())
    .List();

With this, I get the error: "Could not find a setter for property 'Street' 
in class 'Dto".

I'm using NHibernate 4.0.4 with fluentNhibernate 6.2.1.

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to