Print Page | Close Window

Find Entity Graph for sub types

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2851
Printed Date: 13-Apr-2026 at 1:46pm


Topic: Find Entity Graph for sub types
Posted By: sarmaad
Subject: Find Entity Graph for sub types
Date Posted: 27-Jul-2011 at 5:18pm
Hi,

I am having issues retrieving the entity graph for a sub type of an entity..

Consider the following scenario:

a Stock is a base entity. a Unit is a sub entity of Stock & a Building is a sub entity of Stock.
all relations are set on the base entity eg: Stock 1 - * StockCompany * - 1 Company

var stocks is a list results from a query (it could contains Units & Buildings)

var stock = stocks.FirstOrDefault();
IList<object> related = null;

var span1 = new EntitySpan(typeof(Stock), EntityRelations.Stock_StockCompany, EntityRelations.Company_StockCompany);
related = Manager.FindEntityGraph(new[] { stock }, new[] { span1 },EntityState.AllButDetached);

the above will fail because the expected type is Stock not Unit or Building.

How can I retrieve the entity graph for any child entity type based on the base entity type?

ta



Replies:
Posted By: DenisK
Date Posted: 29-Jul-2011 at 11:59am
Hi sarmaad;

This may be a bug but I will confirm. It looks like for now, you have to do the following workaround.

1. Create EntityRelations.Unit_StockCompany and EntityRelations.Building_StockCompany. 

2. You can do so by going to your EntityRelations partial class inside your IB.Designer.cs and just copy paste the code for EntityRelations.Stock_StockCompany and change it to Unit and Building. 

3. It's probably safer to place this new EntityRelations to a different class where you can create another EntityRelations partial class.

4. And do the following logic to create a different EntitySpan depending on the type.

if (stock is Stock) {
  var span1 = new EntitySpan(typeof(Stock), EntityRelations.Stock_StockCompany, EntityRelations.Company_StockCompany);
}

if (stock is Unit) {
  var span1 = new EntitySpan(typeof(Unit), EntityRelations.Unit_StockCompany, EntityRelations.Company_StockCompany);
}

if (stock is Building) {
  var span1 = new EntitySpan(typeof(Building), EntityRelations.Building_StockCompany, EntityRelations.Company_StockCompany);
}

Please let me know whether this works for you or not. I'll do more investigation on my end to find out whether this is a bug and if there's a better workaround.



Print Page | Close Window