Click here to Skip to main content
15,885,740 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
Salam.o.alaikum,

I am developing an Silverlight application, i have connected to my database through a WCF Data Service.. I can succeffuly get a table using

XML
var query1 = (from s in catx.Traders where s.BranchCode == selectedBranchCode select s)  ;
var dquery1 = (query1) as DataServiceQuery<CatsMainService.Trader> ;
dquery1.BeginExecute(AccountsLoaded, dquery1);



i want to get a single column of this table... so i tried

XML
var query1 = (from s in catx.Traders where s.BranchCode == selectedBranchCode select s.Accounts)  ;
var dquery1 = (query1) as DataServiceQuery<CatsMainService.Trader> ;
dquery1.BeginExecute(AccountsLoaded, dquery1);



'Accounts' is my column name...
I am getting nullReferenceException at BeginExecute() because query1 is not being translated.. it says
"{Error translating Linq expression to URI: Can only specify query options (orderby, where, take, skip) after last navigation.}"

I googled... and tried this thing with many other queries... but had the same exception... kindly correct me... where i m mistaking...

Thanks
Posted

1 solution

I would guess that CatsMainService.Trader in DataServiceQuery<CatsMainService.Trader> should be changed to the type of the Accounts column.
 
Share this answer
 
Comments
kas07 20-Apr-11 6:50am    
couldnt get u bro... can u please ellaborate?
dasblinkenlight 20-Apr-11 8:46am    
From here: http://msdn.microsoft.com/en-us/library/cc646677.aspx, class DataServiceQuery<TElement>, TElement [is the] type of results returned by the query. Your first query (the one that works) returns rows of type CatsMainService.Trader. Your second query returns rows of another type (whatever is the type of the Accounts column), so you should change the second line of your second example to match that type, whatever it is. For example, if s.Accounts is a string, the second line should be var dquery1 = (query1) as DataServiceQuery<string> ;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900