我得到一个错误:我正在使用实体框架,wcf。WCF,Linq错误:不能将类型System.linq.iorderedQueryable <>隐式转换为System.Collection.Generic.List <>
Error:cannot implicitly convert type System.linq.iorderedQueryable<xDataModel.Info> to System.Collection.Generic.List<xServiceLibrary.Info>
下面是我的代码:
WCF服务:
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;
}
}
接口:
namespace xServiceLibrary
{
[OperationContract]
List<Info> GetScenario();
}
类:
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; }
}
}
更新:(2) 我有两个类库文件。 一个是xDataModel命名空间,我在其中创建了xmodel.edmx文件。 其次是我在实现Wcf服务的xServiceLibrary命名空间。 我已将xDataModel.dll文件附加到我的xServiceLibrary中,以便我可以查询我的EF模型。
我无法理解这个概念。任何帮助,将不胜感激。
为什么有两个不同的类“DataModel.Info”和“ServiceLibrary.Info”具有相同的定义但名称空间不同? – mellamokb 2012-04-23 21:43:36
'qinfo'是什么类型?这听起来像是你有一个类型不匹配,因为'qinfo'实际上不是一个'Info'对象。 – Tejs 2012-04-23 21:43:56