views:

30

answers:

1

Hi I found problem with EF.

Here is my Model

I loaded asset:

POCO.Asset asset = _context.Assets.Where(a => a.UID == assetUid).First();

then I go through all properties

foreach (POCO.Property p in asset.Properties) /* request to db */ { /*...*/ }

categories:

foreach (POCO.Category p in > asset.Categories) /* request to db */ { /*...*/ }

related assets:

foreach (POCO.Relation relatedAsset in entityAsset.Relations) /* request to db */ { /*...*/ }

all navigation properties work fine. I can see request to db through profile. everything is good.

but if I go through Relations and trying to load RelatedAssetProperties then I have a problem. Basically my Asset has 4 relations and each relation has 2-3 properties.

foreach (POCO.Relation relatedAsset in entityAsset.Relations) /* request to db */
{
 /**/
 ICollection<RelatedAssetProperty> rap = relatedAsset.RelatedAssetProperties;
 foreach (RelatedAssetProperty relatedAssetProperty in rap)  /* request to db */
 {
  /**/
 }

}

During RelatedAssetProperties execution I see all 4 requests to db to get properties. I run all requests in SQL manager and each returns data.

But for some reason only for first relation rap has items (RelatedAssetProperty). For other Relations it is empty.

And I do not know why.

+2  A: 

Can you make sure that your entities have a primary key which makes sense ? I had a similar problem in a view where only the first recordset in the DB was returned.

ram
yes problem was in primary key
Cherven