WCF/WF - WCF dataContracts and LINQ to SQL errors

Asked By Jason on 16-Aug-10 02:47 PM
Iam trying to create a basic WCF service library web service which connects to a database via LINQ to SQL and returns list of DataContract marked objects but I keep recieving this error:

Error    1    Cannot implicitly convert type 'System.Linq.IQueryable<CwkServer.getCarDetails>' to 'System.Collections.Generic.List<CwkServer.getCarDetails>'. An explicit conversion exists (are you missing a cast?)    C:\Users\Cameron\Documents\Visual Studio 2008\Projects\CwkServer\CwkServer\CwkService.cs    34    22    CwkServer

I feel its just a basic error on my part but cant see it. Here is my code

     public List<getCarDetails> getDetails()
       List<getCarDetails> details = from list in db.Listings
           select new getCarDetails
             CarName = list.CarType.CarTypeName,
             NumDoors = list.CarType.NumberOfDoors,
       return details;


    public class getCarDetails
      string carName;
      int numDoors;

      public string CarName
        get { return carName; }
        set { carName = value; }

      public int NumDoors
        get { return numDoors; }
        set { numDoors = value; }

Any advice would be greatly appreciated, kind of hit a brick wall with it now

Web Star replied to Jason on 16-Aug-10 04:09 PM

What is happening is that you are returning an IEnumerable (of one element) of IEntitySet<getCarDetails> types (the type: IEnumerable<IEntitySet<getCarDetails>>).

You should get an IEnumerable<getCarDetails> and it will be converted to IQueryable<getCarDetails> by the AsQueryable method: