I am getting an error : i am using entity framework, wcf.
Error:cannot implicitly convert type System.linq.iorderedQueryable<xDataModel.Info> to System.Collection.Generic.List<xServiceLibrary.Info>
Below are my code:
WCF Service:
namespace xServiceLibrary
{
public List<Info> GetScenario()
{
xEntities db = new xEntities();
var query = from qinfo in db.Infoes
select qinfo;
//return query.Cast<Info>().ToList(); (not working)
//return query.toList(); (not working)
return query;
}
}
Interface:
namespace xServiceLibrary
{
[OperationContract]
List<Info> GetScenario();
}
Class:
namespace xServiceLibrary
{
[DataContract]
public class Info
{
[DataMember]
public int Scenario_Id;
[DataMember]
public string Scenario_Name { get; set; }
[DataMember]
public string Company_Name { get; set; }
}
}
update:(2)
I have two class library files.
One is xDataModel namespace in which i have created xmodel.edmx file.
second is xServiceLibrary namespace where i am implementing Wcf Service.
i have attached the xDataModel.dll file in my xServiceLibrary so that i could query my EF Model.
i am not able to understand the concept. any help would be appreciated.
The problem is that you have two different classes, both called
Info, both in scope at the time you run your query. This is a very very bad thing, especially if you thought they were the same class.If
DataModel.InfoandServiceLibrary.Infoare the same class, you need to figure out why they are both in scope at the same time and fix that.If they are different classes, you need to be explicit about which one you are trying to return. Assuming that your EF model includes a set of
DataModel.Infoobjects, your options there are:List<DataModel.Info>which you can get by callingquery.ToList()Return a
List<ServiceLibrary.Info>which you can get by copying the fields from yourDataModel.Infoobjects:Return something else, such as your custom DTO object, similar to #2 but with only the specific fields you need (e.g. if
ServiceLibrary.Infois a heavy object you don’t want to pass around.In general, though, your problem is centered around the fact that the compiler is interpreting
List<Info>asList<ServiceLibrary.Info>and you probably don’t want it to.