2013-12-08 53 views
1

我想返回兩種類型的調用方法,我知道我們不能在WCF RIA中使用或引用。域服務返回自定義類結果

我創建了一個自定義的類來獲取必要的信息是這樣的:

[DataContract] 
    public class Web_GetPrivilegesResult { 
     [Include] 
     [DataMember] 
     public List<tblPrivilege> ResultList { get; set; } 

     [DataMember] 
     public Guid? ParentGroupID { get; set; } 
    } 

    [Invoke] 
    public Web_GetPrivilegesResult Web_GetPrivileges(Guid id, bool isSuperAdmin, bool isEnable, bool returnAccessListIfDisbaled) { 
     ... 
    } 

在客戶端(Silverlight應用程序),當函數被調用時,它只返回ParentGroupID - ResultList不retruned。我如何糾正這一點?

UPDATE

上次更改代碼:

[DataContract] 
    public class Web_GetPrivilegesResult { 
     //[System.ComponentModel.DataAnnotations.Composition] 
     //[Include] 
     [DataMember] 
     public List<tblPrivilege> Result { get; set; } 

     [DataMember] 
     public Guid? ParentGroupID { get; set; } 
    } 

    //[Query] 

    [Invoke] 
    public Web_GetPrivilegesResult Web_GetPrivileges(Guid id, bool isSuperAdmin, bool isEnable, bool returnAccessListIfDisbaled) { 
     tblUsersAndGroup usersAndGroup = new tblUsersAndGroup() { ID = id, IsSuperAdmin = isSuperAdmin, IsEnable = isEnable }; 

     Guid? parentGroupID; 
     List<tblPrivilege> result = GetPrivileges(usersAndGroup, out parentGroupID, returnAccessListIfDisbaled, this.DataContext); 

     //System.Data.Linq.DataLoadOptions options = new System.Data.Linq.DataLoadOptions(); 
     //options.LoadWith<Web_GetPrivilegesResult>(q => q.Result); 
     //this.DataContext.LoadOptions = options; 

     //List<Web_GetPrivilegesResult> res = new List<Web_GetPrivilegesResult>(); 
     //res.Add(new Web_GetPrivilegesResult() { ParentGroupID = parentGroupID, Result = result }); 


     return new Web_GetPrivilegesResult() { ParentGroupID = parentGroupID, Result = result }; 

    } 

感謝

+0

沒有返回它是空的? –

+0

沒有在Silverlight中生成ResultList屬性,我無法訪問它 –

回答

1

由於使用[Include]屬性,在查詢的方法,你必須確保相關的實體實際上是用裝在查詢中包含方法。

您需要明確請求(使用LINQ到實體),對於ResultList propertiy每個Web_GetPrivilegesResult實體的數據從數據庫中檢索,使用Include方法查詢,像這樣:

public IQueryable<Web_GetPrivilegesResult> GetPrivilegesResult() 
{ 
    return this.ObjectContext.Web_GetPrivilegesResult.Include("ResultList"); 
} 

UPDATE:

而就在return結束在Web_GetPrivileges(Guid id, bool isSuperAdmin, bool isEnable, bool returnAccessListIfDisbaled)方法中添加.Include("ResultList")

UPDATE2:

你可以看到thisthis爲LINQ2SQL相當於Include()

+0

我正在使用LinqToSqlDomainService,並且我有靜態函數與實體一起工作,並且獲取結果tblPrivilege列表,我該如何使用這種方式來表示?謝謝 –

+0

編寫完整代碼的Web_GetPrivileges方法問題 –

+0

其中Include方法,我找不到它,你可以看到Include方法不是Web_GetPrivilegesResult類的成員,並且Web_GetPrivilegesResult不是datacontext實體... –

相關問題