cjbiggs wrote:
Thanks for that information. But the two Entities are not related in the database.
Ohh, I see.
cjbiggs wrote:
1.) Make two Entities related in code (They are not related in the database or using the designer).
Create a new EntityRelation at code and specify the two entity/fields that involve the relation.
EntityRelation newRelation = new EntityRelation(
SalesOrderFields.SalesOrderId, SalesOrderDetailFields.SalesOrderId, RelationType.OneToMany);
cjbiggs wrote:
2.) Use PrefetchPath on the Dynamic relationship from Step #1
No. No in entity fetches. See, relation is for filtering or sorting on related entities. PrefetchPaths is fetch related objects and is inherent to Entity objects. So you can not create a prefetchpath on the fly.
cjbiggs wrote:
3.) Get a custom resultset containing both Entities
No targeting entities. But you can use DynamcLiist that targets DataTable (see my liink in my previous post). Look for instance, suppose I dont have SalesOrder -> SalesOrderDetail relation and I want to fetch fields from both entities. I can use DynamicList and a new custom relation:
EntityFields2 fields = new EntityFields2(2);
fields.DefineField(SalesOrderDetailFields.LineTotal, 0);
fields.DefineField(SalesOrderFields.CustomerId, 1);
EntityRelation newRelation = new EntityRelation(
SalesOrderFields.SalesOrderId, SalesOrderDetailFields.SalesOrderId, RelationType.OneToMany);
IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(newRelation);
DataTable results = new DataTable();
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchTypedList(fields, results, bucket);
}
Hope helpful