1
我創建了一個WCF dataservice類來將查詢結果返回給javascript客戶端。這裏是我的dataservice的僞代碼:如何從wcf dataservice返回相關實體
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中,它表示延期的相關實體。
我需要做些什麼來讓這些相關實體返回給客戶端?謝謝!