Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my web service method
C#
public void GetObservation(IQueryable<tblObservation> LstObservation)
     {
        //Some code

     }


When i am calling this service method i am getting compilation error.

C#
public void UploadData()
  {
      RSCRIMLocalDBEntities dtobj = new RSCRIMLocalDBEntities();

      var ObservationTypDtls = (from u in dtobj.tblObservations
                                select u);
     // IEnumerable<tblObservation> LstObservation = ObservationTypDtls.ToList().AsEnumerable();

      List<tblObservation> LstObservation = new List<tblObservation>(ObservationTypDtls);

      SCRIMWCFDataClient.ServiceReference1.DataServiceClient Dt = new DataServiceClient();

      Dt.GetObservation(LstObservation.AsQueryable());//Compilation error

}


C#
cannot convert from 'System.Linq.IQueryable<RSOM.tblObservation>' to 'SCRIMWCFDataClient.ServiceReference1.tblObservation[]'

C#
the best overloaded method match for GetObervation(tblObervations[]) has some invalid arguments
This is the error i am getting
Posted
Updated 6-Jan-16 18:06pm
v6

1 solution

You need to use an IQueryable<t> as an argument to the method. In your code you are using a List<t>. You can make use of AsQueryable method to make the call. Like this:

C#
Dt.GetObservation(LstObservation.AsQueryable());


List<t> class does not implement the IQueryable<t> interface and hence you are getting the error.

Updated based on OP comment:
When you have added the service reference, the collection type was set to Array. This is why the method parameter is now displayed as Array. You can either configure the service reference using Service Reference Configure dialog[^] and then use appropriate argument type or change the method call as:

C#
Dt.GetObservation(LstObservation.ToArray());
 
Share this answer
 
v4
Comments
mithun286 6-Jan-16 23:52pm    
U mean this is the changes i need to do in Upload Method

IQueryable<tblObservation> LstObservation = ObservationTypDtls;

is that right???
dan!sh 6-Jan-16 23:54pm    
Just change the method call as mentioned in the response above.
mithun286 6-Jan-16 23:57pm    
Still the error is same.I only changed method call as explained
dan!sh 7-Jan-16 0:00am    
Can you update the question with updated code complete error details.
mithun286 7-Jan-16 0:06am    
cannot convert from 'System.Linq.IQueryable<rsom.tblobservation>' to 'SCRIMWCFDataClient.ServiceReference1.tblObservation[]'

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