Question

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?

Was it helpful?

Solution

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);

OTHER TIPS

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)
   {
   }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top