【发布时间】:2014-04-02 23:20:00
【问题描述】:
我在 EF 中作为实体的类是:
Cat { Id, ParentId, Name, ImageUrl, ...}
Tree { Id , ParentId, Name}
还有其他选择吗:
var trees= (from rs in _db.ItemCats
where rs.ParentId == null
select new Tree
{
Id = rs.Id,
ParentId = rs.ParentId,
Name = rs.Name
}).ToList();
类似:
var trees= (from rs in _db.ItemCats
where rs.ParentId == null
select new
{
rs.Id, rs.Name,
rs.ParentId
}).Cast<Tree>().ToList();
但是得到:
无法将类型“匿名类型”转换为类型“Meha3.Models.Tree”。 LINQ to Entities 仅支持转换 EDM 原语或枚举 类型
【问题讨论】:
-
Cat是Tree的子类型吗? -
您需要添加更多解释以便用户理解
标签: c# linq entity-framework casting