Join between tables and result to another class

19 views
Skip to first unread message

Christian I.

unread,
Sep 27, 2012, 4:09:44 PM9/27/12
to nhu...@googlegroups.com
Hello,

I have this mapping (see below). I'd create a List<MyClass> with some properties of Product and other of ProductDetail.

How can I do this ?

Thanks,


    public class MyClass
    {
        public string FieldA { get; set; }
        public string FieldB { get; set; }
        public string BieldC { get; set; }
        public string BieldD { get; set; }
    }



Mappging :

    public class ProductMap : ClassMap<Product>
    {
        public ProductMap()
        {
            Id(x => x.Id).GeneratedBy.Native();
            Map(x => x.Code)
                .Length(20)
                .Unique()
                .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");
            HasManyToMany(x => x.Details)
                .AsSet()
                .Cascade
                .SaveUpdate()
                .Table("ProductsProductsDetails");
        }
    }


    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);
            HasManyToMany(x => x.Products)
                .AsSet()
                .Inverse()
                .Table("ProductsProductsDetails");
        }
    }

Pete Appleton

unread,
Sep 28, 2012, 5:25:27 AM9/28/12
to nhu...@googlegroups.com

Take a look at  http://nhforge.org/doc/nh/en/index.html#queryqueryover-projections, in particular the AliasToBean<T> transformer is probably what you're after.

 

Pete

--
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/-/qQa2M-KllyYJ.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Reply all
Reply to author
Forward
0 new messages