New Posts New Posts RSS Feed: Find Entity Graph for sub types
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Find Entity Graph for sub types

 Post Reply Post Reply
Author
sarmaad View Drop Down
Newbie
Newbie


Joined: 18-Jul-2010
Location: Sydney
Posts: 15
Post Options Post Options   Quote sarmaad Quote  Post ReplyReply Direct Link To This Post Topic: Find Entity Graph for sub types
    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
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down