Domain Service Return Custom Class Result

276 views Asked by At

I want return two types to the calling method, i know that we cannot use out or ref in WCF RIA.

i have created a custom class to get necessary info like this :

    [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) {
        ...
    }

On the client side (silverlight application) when the function is called, it returns only ParentGroupID - ResultList isn't retruned. how can i correct this ?

UPDATE

Last changed Codes :

    [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 };

    }

thanks

1

There are 1 answers

3
SeyedPooya Soofbaf On

Because of using [Include] attribute, In the query method, you must ensure that the associated entities are actually loaded by using the Include method on the query.

You will need to explicitly request (using LINQ to Entities) that the data for the ResultList propertiy on each Web_GetPrivilegesResult entity are retrieved from the database, using the Include method in the query, like so:

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

UPDATE:

Just add .Include("ResultList") at the end of the return in your Web_GetPrivileges(Guid id, bool isSuperAdmin, bool isEnable, bool returnAccessListIfDisbaled) method !

UPDATE2:

You can see this and this for Linq2SQL equivalent of Include()