带有MVC 4和WebApi的实体框架 [英] Entity Framework with MVC 4 and WebApi

查看:82
本文介绍了带有MVC 4和WebApi的实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在学习实体框架,同时尝试数据库优先方法。

我添加了一个实体模型该项目并使用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.

推荐答案

通过在上下文类构造函数中禁用延迟加载功能解决了这个问题,如下所示: br $>


Resolved this by disabling the lazy loading functionality in context class constructor as below,

this.Configuration.LazyLoadingEnabled = false;


这篇关于带有MVC 4和WebApi的实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆