I don't know how to project three levels onto the top using NH, but
you can use
LINQ to give you a read-only projection of an objects grandchildren.
Notice below,
the grandparent TableA contains a collection of all of its
grandchildren in CollectionC.

public class TableA
{
        public int id { get; set; }
        public string Name { get; set; }
        public IList<TableB> CollectionB { get; set; }

        public IList<TableC> CollectionC
        {
                get
                {
                        return (from b in CollectionB
                                        from c in b.CollectionC
                                        select c).ToList<TableC>();
                }
        }
}

public class TableB
{
        public int id { get; set; }
        public string Name { get; set; }
        public IList<TableC> CollectionC { get; set; }
}

public class TableC
{
        public int id { get; set; }
        public string Name { get; set; }
}


[Test]
public void can_aggregate_collections()
{
        TableA myA = new TableA()
        {
                id = 1,
                Name = "a1",
                CollectionB = new List<TableB>()
                {
                        new TableB()
                        {   id=1,
                                Name="b1",
                                CollectionC = new List<TableC>()
                                {
                                        new TableC() { id=1,Name="a1b1c1"},
                                        new TableC() { id=2,Name="a1b1c2"}
                                }
                        },
                        new TableB()
                        {   id=2,
                                Name="b2",
                                CollectionC = new List<TableC>()
                                {
                                        new TableC() { id=1,Name="a1b2c1"},
                                        new TableC() { id=2,Name="a1b2c2"},
                                        new TableC() { id=2,Name="a1b2c3"}
                                }
                        }
                }
        };

        Assert.AreEqual(5, myA.CollectionC.Count);
}




On Oct 21, 10:29 pm, Asela Gunawardena <[email protected]> wrote:
> Hi All,
>
> Consider the following table structure
>
> TableA - TableAB - TableB - TableC - TableCB [where as TableAB and
> TableBC are tables introduced resolve many to many relationships].
>
> my question is if i define an object structure like
>
> class A
> {
>   //Propertise
>   IList<C> C
>
> }
>
> is there a way of directly mapping class A to C directly [bag / set
> statements]; as Table A has a collection of C records in database
> level.
>
> thanx !

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
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