Typecasting EnityObject
- by AJ
Hello,
I'm new to C# and am stuck on the following. I have a Silverlight web service that uses LINQ to query a ADO.NET entity object. e.g.:
[OperationContract]
public List<Customer> GetData()
{
using (TestEntities ctx = new TestEntities())
{
var data = from rec in ctx.Customer
select rec;
return data.ToList();
}
}
This works fine, but what I want to do is to make this more abstract. The first step would be to return a List<EntityObject> but this gives a compiler error, e.g.:
[OperationContract]
public List<EntityObject> GetData()
{
using (TestEntities ctx = new TestEntities())
{
var data = from rec in ctx.Customer
select rec;
return data.ToList();
}
}
The error is:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<SilverlightTest.Web.Customer>' to 'System.Collections.Generic.IEnumerable<System.Data.Objects.DataClasses.EntityObject>'. An explicit conversion exists (are you missing a cast?)
What am i doing wrong?
Thanks,
AJ