Asp.net mvc 实体框架类型错误
我以这种方式使用EF获取两个表的数据,并将其转换为列表以将其传递给视图,我正在mvc4中工作,但我得到以下错误:Asp.net mvc 实体框架类型错误,asp.net-mvc,entity-framework,Asp.net Mvc,Entity Framework,我以这种方式使用EF获取两个表的数据,并将其转换为列表以将其传递给视图,我正在mvc4中工作,但我得到以下错误: Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<EFwithMVC.Models.dc_tp_personnel>' to 'System.Collections.Generic.List<EFwithMVC.Models.bc_limsEntities>'
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<EFwithMVC.Models.dc_tp_personnel>' to 'System.Collections.Generic.List<EFwithMVC.Models.bc_limsEntities>' C:\Users\Administrator\Documents\Visual Studio 2010\Projects\EFwithMVC\EFwithMVC\Controllers\PersonellController.cs 119 34 EFwithMVC
错误1无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”C:\Users\Administrator\Documents\Visual Studio 2010\Projects\EFwithMVC\EFwithMVC\Controllers\PersonellController.cs 119 34 EFwithMVC
这是我的密码:
public List<bc_limsEntities> GetTwoTableData()
{
using (var db = new bc_limsEntities())
{
return (from x in db.dc_tp_personnel.Include("dc_toutside_test")
where x.PersonId == 1
select x).ToList();
}
}
public List GetTwoTableData()
{
使用(var db=new bc_limsEntities())
{
返回(来自数据库中的x。dc\U tp\U人员。包括(“dc\U toutside\U测试”)
其中x.PersonId==1
选择x).ToList();
}
}
请帮帮我,我不知道为什么会出现这个错误,只要看看你的问题就知道你返回的是.dc\u tp\u personal对象的集合
return (from x in db.dc_tp_personnel.Include("dc_toutside_test")
where x.PersonId == 1
select x).ToList();
但是在您的返回类型中,您定义了列表
,这是上下文,因此您得到的异常是因为您正在重新发送dc\u tpu人员
,但是返回类型是bc\u limentities
如果您使用返回类型dc\u tpu人员
l,您不应该得到该异常