WCF/WF - WCF dataContracts and LINQ to SQL errors

Asked By Jason
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

cwkService
     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;
}

ICwkService

  [DataContract]
    public class getCarDetails
    {
      string carName;
      int numDoors;

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

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

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

Thanks
Jason
  Web Star replied to Jason
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:

Create New Account
help
SQL Server 2008 Standard and Visual Studio 2008 Professonal SQL Server I have retailed copies VS 2008 Pro and SQL 2008 Standard. While in VS 2008 I tried to create a SQL database in a ASP.Net 3.51 Web application want to down grade my SQL Server. I spent good money on the SQL Server 2008. Is there a work around option where I can use VS 2008 and SQL Server
MSDN Library for Visual Studio 2008 .NET Framework where can I download MSDN Library for Visual Studio 2008. I need an offline visual studio 2008 help documentation solution. thanks nick Visual Studio General Discussions Visual Studio 2008 (1) Latest
Do I have Visual Studio 2008? Icon does not appear, but. . . .NET Framework I have Visual Studio 2005 on my computer. Recently I downloaded Visual Studio 2008 Express (I think). But there is no icon for Visual Studio 2008 on the desktop
Microsoft Webcasts SQL Server 2008 Visual Studio 2008 .NET Framework Do want to attend the Microsoft SQL Server 2008 and Visual Studio 2008 sessions at your home PC?. Yes now it is possible. Microsoft has scheduled a Webcasts
Upgrade Visual Studio 6 to Visual Studio 2008? .NET Framework I have Visual Studio 6 Professional. Can I install the upgrade version of Visual Studio 2008 Professional? I cannot find this info on Microsoft's website. Visual Studio General