【发布时间】:2019-04-02 06:50:48
【问题描述】:
总的来说,我是 EF、Linq 和 C# 的新手,我一直坚持开发以下内容。 我无法将数据映射到这样的结构中:
Id,
Actions [
Action1,
Action2,
Action3
]
我有 2 个这样的 DTO 类:
public class TestDTO
{
public int TestId { get; set; }
public TestDTO2[] Actions { get; set; }
}
和
public class TestDTO2
{
public int TestActionId { get; set; }
public DateTime? StartDate { get; set; }
...
}
我已经将对 DB 的调用分离到名为 BusinessLogic 的文件中,我这样做是这样的:
public IQueryable<TestDTO> GetNested(Filter filter)
{
var query =
from a in db.Table1.AsQueryable()
select new TestDTO
{
TestId = a.Id,
Actions = (
from b in db.Table2.AsQueryable()
where a.Id == b.TestId
select new TestDTO2
{
TestActionId = b.TestActionId,
StartDate = b.StartDate
}
).ToArray()
};
return query;
}
我收到以下错误:
LINQ to Entities 无法识别方法 'Project.Core.Models.TestDTO2[] ToArrayTestDTO2' 方法,并且该方法无法转换为存储表达式。
【问题讨论】:
标签: entity-framework linq dto