【发布时间】:2012-01-13 20:30:59
【问题描述】:
我创建了一个 WCF 数据服务类来将查询结果返回给 javascript 客户端。这是我的数据服务的伪代码:
public class MyDataService : DataService<MyEntities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("MyGetMethod", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServicePRotocolVersion.V2;
}
[WebGet(UriTemplate = "{SomeID}"]
public IEnumerable<Models.Customer> MyGetMethod(int? someID)
{
if (someID == null) throw new DataServiceException("ID not specified");
MyEntities context = this.CurrentDataSource;
context.ContextOptions.LazyLoadingEnabled = false;
var q = Linq statement which queries for a collection of entities from context
IEnumerable<Models.Customer> result = q;
foreach (Models.Customer customer in result)
{
if (!customer.Contacts.IsLoaded)
customer.Contacts.Load();
}
return result;
}
}
来自客户端请求的调用结果为 json。当我在 dataservice 中调试 get 方法时,结果在一个名为 WrappedRelatedEntities 的属性中扩展了特定的相关数据,但在返回给客户端的 json 中,对于它所说的相关实体,它表示延迟。
我需要做什么才能将这些相关实体返回给客户?谢谢!
【问题讨论】:
标签: json entity-framework wcf-data-services