views:

47

answers:

2

I have this code:

       public static IEnumerable<dcCustomer> searchCustomer(string Companyname)
    {
        TestdbDataContext db = new TestdbDataContext();


        IEnumerable<dcCustomer> myCustomerList = (from Customer res
                                                  in db.Customers
                                                  where res.CompanyName == Companyname
                                                  select res);

        return myCustomerList;



    }

And whatever i try i keep getting the convert error.

Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ConnectionWeb.Customer>' to 'System.Collections.Generic.IEnumerable<ConnectionWeb.DAL.dcCustomer>'. An explicit conversion exists (are you missing a cast?) \\srv01\home$\Z****\Visual Studio 2008\Projects\ConnectionWeb\ConnectionWeb\DAL\dcCustomer.cs 63 20 ConnectionWeb

I want to try get myCustomerList to keep the values in an enumerator and return it.

+2  A: 

the problem is the you are expecting to return a DAl.dcCustomer type, but the linq statement is returning a ConnectionWeb.Customer type...

You could overcome this by changing:

IEnumerable<dcCustomer> myCustomerList = 
(from Customer res
   db.Customers
   where res.CompanyName == Companyname
   select res);

to:

IEnumerable<dcCustomer> myCustomerList = (from Customer res
  in db.Customers
  where res.CompanyName == Companyname
  select new dcCustomer(){
   //set properties here...
  });

HTH

Sunny
Thanks for your answer!
Younes
+1  A: 

Looks to me like db.Customers contains objects of type ConnectionWeb.Customer and not ConnectionWeb.DAL.dcCustomer like you assume.

Seventh Element