开发者

Entity Framework does not return object

开发者 https://www.devze.com 2023-01-04 21:07 出处:网络
Hi I found problem with EF. Here is my Model I loaded asset: POCO.Asset asset = _context.Assets.Where(a => a.UID == assetUid).First();

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开发者_JAVA百科.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消