Irakli Lekishvili
Irakli Lekishvili

Reputation: 34158

How to return List<int> from domain service

Hello guys im using WCF RIA Services i have domain services where i wrote this method

public List<int> GetActionIDs() 
    {
        return (from d in ObjectContext.actions select d.id).ToList();
    }

How i can get this List in client side? This does not works :

List<int> = db.GetActionIDs();

any suggestions?

Upvotes: 1

Views: 1651

Answers (2)

Masoomian
Masoomian

Reputation: 752

inside DomainSrvice

[Query]    
public List<Action> GetActionIDs()     
 {         
   List<Action> result =  (  
                           from a in ObjectContext.actions                                     
                            select new action                                   
                             {                        
                                ID = a.ID
                             }
                        ).ToList(); 
   return result ;
 }

Silverlight

DomainService1 DS = new  DomainService1();
LoadOperation<Action> LoadOp = Ds.Load(Ds.GetActionIDsQuery());

LoadOperation.Completed += new EventHandler((s,e)=>{
   foreach (Action item in LoadOp.Entities)
   {
   }
});

Upvotes: 0

Pavel Gatilov
Pavel Gatilov

Reputation: 7661

First of all, you should read the RIA Services manual, because you don't realize that service calls in Silverlight are asynchronous.

In your case, you should

Add InvokeAttribute to your operation in the service:

[Invoke]
public List<int> GetActionIDs() 
{
    return (from d in ObjectContext.actions select d.id).ToList();
}

Then, all calls to DomainContext are asynchronous, so you get your results in the callback:

db.GetActionIDs(operation =>
                {
                  //TODO: check the operation object for errors or cancellation

                  var ids = operation.Value; // here's your value

                  //TODO: add the code that performs further actions
                }
                , null);

Upvotes: 1

Related Questions