实体类的外键的表 [英] Entity class with Foreign key tables

查看:281
本文介绍了实体类的外键的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的ASP.NET Web API服务模式是由是由ADO.NET实体框架数据模型数据库的第一种方法生成的实体类的。

In ASP.NET Web API Service model is made of Entity classes that are generated by ADO.NET Entity Framework Data Model database first approach.

在模型被返回到服务响应客户端,还可以返回从外键表中的数据。例如:客户表包含联系人表的外键表

When the Model is returned to the client in Service response, data from the Foreign key tables is also returned. For example: Customer table contains Contact table as the Foreign key table.

实体框架生成POCO(实体),如下图所示。

The Entity Framework generating the POCO (Entity) as below.

public partial class Customer
{
public int Id {get;set;}
public FirstName {get;set}
public LastName {get;set;}

//Foreign key table
public virtual Contact Contact {get;set;}
}

服务模式是:

public class Customer
{
        public Customer customer {get;set;}
}

从被创建的模型类的实例的API的控制器,数据是从数据库检索并返回给客户机。

From the API Controller an instance of the model class is created, data is retrieved from the database and returned to the client.

的问题是当所有从客户表中的记录或单个记录被返回到客户端,它从外键(参考的)表中的数据返回为好。
说有在联系表约100触点,当一个资源请求从Web服务客户端发出的,返回的包括从客户表中的所有数据,以及这些数据。

The issue is "when all the records or single record from the Customer table is returned to the client, it is returning the data from Foreign key(Referenced) tables as well. Say there are about 100 contacts in Contact table, when a request for one resource is made from the web service client, the data returned is including all the data from the Customer table as well.

帮助AP preciated来解决这个问题。

Help appreciated to address this behavior.

问候

推荐答案

设置LazyloadingEnabled属性​​设置为False为ObjectContext中已经解决了这个问题。

Setting the "LazyloadingEnabled" property to False for the ObjectContext has resolved the issue.

context.Configuration.LazyLoadingEnabled = false;

在更多的http:// msdn.microsoft.com/en-us/library/vstudio/dd456846(v=vs.100).aspx
         http://msdn.microsoft.com/en-ie/data/jj574232.aspx

这篇关于实体类的外键的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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