DharaPPatel
DharaPPatel

Reputation: 12763

WCF and Linq Service

i am making wcf rest service using linq. i wanna use stored procedure to access the database in linq..i came to know to about the accessing syntax but ToList() property i m not finding in my project..can anybody suggest me the solution ?


Code : [OperationContract] [WebGet(UriTemplate = "/CList/")] public CList[] GetCList() {string strConnection = ConfigurationManager.ConnectionStrings["HConnectionString"].ConnectionString;

    HDataContext dc = new HDataContext(strConnection);

    string strUrl = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.ToString();

    var result = from cust in dc.tbl_Customer_Masters

                 select new CList
                 {
                     RMSID = 0,
                     CID = cust.C_Id,
                     FIRSTNAME = cust.C_First_Name,
                     LASTNAME = cust.C_Last_Name,

                 };

    return result.ToArray(); }

Upvotes: 0

Views: 261

Answers (2)

Brian Driscoll
Brian Driscoll

Reputation: 19635

The ToList() method is only defined for objects that inherit from System.Linq.Enumerable or that implement the IEnumerable interface. So, you need to make sure of the following:

  1. You have a reference to the appropriate DLL in your project (it's in System.Core, so you should have a reference by default unless you removed it).
  2. You have a using directive for the System.Linq namespace in your file.
  3. The object you're trying to call ToList on actually inherits from System.Linq.Enumerable or implements the IEnumerable interface.

Upvotes: 1

Bas
Bas

Reputation: 27115

ToList is an Extension Method. This means it's not actually in the containing class. You need to add a using statement to your code to use this feature.

using System.Linq;

Then you can call ToList() on any IEnumerable

Upvotes: 0

Related Questions