实体框架不返回对象
您好,我发现 EF 有问题。
这是
我加载资产的模型:
POCO.Asset asset = _context.Assets.Where(a => a.UID == assetUid).First();
然后我浏览所有属性
foreach (POCO.Property p in asset.Properties) /* request to db */ { /*...*/ }
类别:
foreach (POCO.Category p in > asset.Categories) /* request to db */ { /*...*/ }
相关资产:
foreach (POCO.Relation relatedAsset in entityAsset.Relations) /* request to db */ { /*...*/ }
所有导航属性都工作正常。我可以通过配置文件看到对数据库的请求。一切都很好。
但如果我浏览“关系”并尝试加载“RelatedAssetProperties”,那么我就会遇到问题。 基本上我的资产有 4 个关系,每个关系有 2-3 个属性。
foreach (POCO.Relation relatedAsset in entityAsset.Relations) /* request to db */
{
/**/
ICollection<RelatedAssetProperty> rap = relatedAsset.RelatedAssetProperties;
foreach (RelatedAssetProperty relatedAssetProperty in rap) /* request to db */
{
/**/
}
}
在RelatedAssetProperties 执行期间,我看到对数据库的所有4 个获取属性的请求。我在 SQL 管理器中运行所有请求,每个请求都返回数据。
但由于某种原因,只有第一个关系说唱才有项目(RelatedAssetProperty)。对于其他关系,它是空的。
我不知道为什么。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否确保您的实体具有有意义的主键? 我在视图中遇到了类似的问题,其中只有第一个返回数据库中的记录集。
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.