无法将类型“匿名类型”强制转换为类型“SkyiSite.Models.Company”
C# code
var ss = (from uu in GetList1.hr().As_user where uu.Tb_person != null && uu.aspnet_Users.aspnet_Membership.IsLockedOut == false && uu.Tb_person.gongkai == true orderby uu.Tb_person.addtime descending select new { id = uu.id, uu.Tb_person.name, uu.Tb_person.sex, uu.Tb_person.degree, nianling = (DateTime.Now.Year - uu.Tb_person.b_nian + 1), nianxian = uu.Tb_person.nianxian, uu.aspnet_Users.aspnet_Membership.IsLockedOut, uu.Tb_person.xueli, addtime = uu.aspnet_Users.LastActivityDate }).[b]Cast<SkyiSite.Models.ModelClass.Company>()[/b].ToList();
SkyiSite.Models.ModelClass.Company的内容跟new出来的是一样的
错误提示
无法将类型“匿名类型”强制转换为类型“SkyiSite.Models.Company”。LINQ to Entities 仅支持强制转换 Entity Data Model 基元类型。
请问怎么解决
谢谢
------解决方案--------------------
var ss = (from uu in GetList1.hr().As_user
where uu.Tb_person != null
&& uu.aspnet_Users.aspnet_Membership.IsLockedOut == false
&& uu.Tb_person.gongkai == true
orderby uu.Tb_person.addtime descending
select new SkyiSite.Models.ModelClass.Company
{
id = uu.id,
uu.Tb_person.name,
uu.Tb_person.sex,
uu.Tb_person.degree,
nianling = (DateTime.Now.Year - uu.Tb_person.b_nian + 1),
nianxian = uu.Tb_person.nianxian,
uu.aspnet_Users.aspnet_Membership.IsLockedOut,
uu.Tb_person.xueli,
addtime = uu.aspnet_Users.LastActivityDate
}).ToList();
试试上面的这种方法