Join multiple tables (eager loading) to POCO

59 views
Skip to first unread message

Nuno Ferreira

unread,
Mar 6, 2015, 8:18:09 AM3/6/15
to simpl...@googlegroups.com
Hi,

I would like to query multiple tables and get the result into my POCO structure.
CatalogRegions table is related to Catalogs table and this one is related to Companies table.
I want to bind my CatalogRegion with the related Catalog and this one with the related Company (catalogRegion.Catalog and catalogRegion.Catalog.Company). catalogRegion.Catalog is ok but catalogRegion.Catalog.Company property is allways null.

Any help?

POCO:

    public class Company
    {
        public Company() { }
        public List<Catalog> Catalogs { get; set; }
        public int CompanyId {get; set;}
        public string Name { get; set; }
    }

    public class CatalogRegion
    {
        public CatalogRegion() { }

        public int CatalogRegionId { get; set; }
        public int CatalogId {get; set;}
        public string Name { get; set; }
        public Catalog Catalog { get; set; }
    }

    public class Catalog
    {
        public Catalog() { }

        public int CatalogId {get; set;}
        public int CompanyId { get; set; }
        public string Name { get; set; }
        public Company Company { get; set; }
        public List<CatalogRegion> CatalogRegions { get; set; }
    }

Query:

CatalogRegion catalogRegion = db.CatalogRegions
                .With(db.CatalogRegions.Catalogs.As("Catalog"))
                .With(db.CatalogRegions.Catalogs.Companies.As("Catalog.Company"))
                .Get(32);


Best regards,
Nuno Ferreira


Kevin Krac

unread,
May 5, 2015, 10:55:56 PM5/5/15
to simpl...@googlegroups.com
I have this same issue and have posted it here: https://groups.google.com/forum/#!topic/simpledata/fX8d45VFwh0

It seems to be quite a basic thing to do so I would suppose that it is me who's doing something wrong. But nobody has so far being able to know what I am doing wrong...

Paul Marfleet

unread,
Jul 16, 2015, 6:44:24 PM7/16/15
to simpl...@googlegroups.com
I believe this isn't possible with Simple.Data 1.x. See the answer to this Stack Overflow question: http://stackoverflow.com/questions/22075508/simple-data-nested-join-retrieval
Reply all
Reply to author
Forward
0 new messages