Typecasting EnityObject
Posted
by AJ
on Stack Overflow
See other posts from Stack Overflow
or by AJ
Published on 2010-03-29T11:57:42Z
Indexed on
2010/03/29
12:03 UTC
Read the original article
Hit count: 448
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
© Stack Overflow or respective owner