Fetch to datatable

Posts   
 
    
mjeduar
User
Posts: 35
Joined: 14-Sep-2012
# Posted on: 17-Oct-2012 03:04:25   

Version 2.5

I am trying to do a join to get the fields of two tables and past those to one Datatable

table 1 is Product table 2 ProductTrapType

With the current code I get the data of the first table but not the field of the second.

definitely I know I am doing something wrong, is this the best way or there is other way to do it, and what am I doing wrong?.

Code:

RelationPredicateBucket filter = new RelationPredicateBucket();

filter.Relations.Add(ProductEntity.Relations.ProductTrapTypeEntityUsingTrapTypeFk,  JoinHint.Left);

DataAccessAdapter adapter = new DataAccessAdapter();  
EntityCollection Product = new EntityCollection(new ProductEntityFactory());

adapter.FetchEntityCollection(Product, filter);

IEntityView2 ProductView = Product.DefaultView;

List<IEntityPropertyProjector> propertyProjectors = new List<IEntityPropertyProjector>();
        propertyProjectors.Add(new EntityPropertyProjector(ProductFields.ProductName, "productname"));
        propertyProjectors.Add(new EntityPropertyProjector(ProductFields.ProductId, "productid"));
        propertyProjectors.Add(new EntityPropertyProjector(ProductFields.TrapTypeFk, "TrapType_FK"));
        propertyProjectors.Add(new EntityPropertyProjector(ProductFields.SetoutMin, "setoutmin"));
        propertyProjectors.Add(new EntityPropertyProjector(ProductFields.SetoutMax, "setoutmax"));
        propertyProjectors.Add(new EntityPropertyProjector(ProductFields.StyleFk, "StyleFk"));

        propertyProjectors.Add(new EntityPropertyProjector(ProductTrapTypeFields.Nametraptype, "Nametraptype"));// I can't get this

        DataTable projectionResults = new DataTable();
        ProductView.CreateProjection(propertyProjectors, projectionResults);
        return projectionResults;
Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 17-Oct-2012 20:12:42   

You are fetching fields from one entity. The join here is used for filtering only. you'd better check the documentation for DynamicLists.

mjeduar
User
Posts: 35
Joined: 14-Sep-2012
# Posted on: 18-Oct-2012 01:47:39   

Thank you DynamicLists worked beautiful.