问题描述
大家好,
我正在学习实体框架,同时尝试数据库优先方法。
我添加了一个实体模型该项目并使用Entity Framework创建了一个API控制器。通过从API控制器中浏览get方法,我发现数据是以json格式获得的,这是预期的。我在数据库中的表有与之关联的外键。
我发现的是参考外键,json包含了表中的数据,也考虑了另一个数据链接的数据使用外键到这个表。
我希望只返回原始表中的数据,而不是来自外表的数据。
任何人都可以提供一些指示。
Hi All,
I'm learning Entity Framework, while trying out Database First Approach.
I added an Entity Model to the project and created an API controller using Entity Framework. By just browsing the get method from the API controller Created I found that the data is obtained in json format which is as expected. My table in the database have foreign keys associated with it.
What I found is with reference to the foreign key, json contains the data from the table in consideration also with the data which is in another data linked to this table with foreign key.
I expect only the data from the original table to be returned back and not the data from the foreign table.
Can anyone please provide some pointers to this.
推荐答案
this.Configuration.LazyLoadingEnabled = false;
这篇关于带有MVC 4和WebApi的实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!