【发布时间】:2017-10-06 23:34:39
【问题描述】:
我有如下三个模型,
public class Team
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Document
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Application { get; set; }
public ICollection<DocumentResponsible> DocumentResponsibles { get; set; }
public string Pcda { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
public class DocumentResponsible
{
public int Id { get; set; }
public int DocumentId { get; set; }
public int TeamId { get; set; }
}
我想编写一个实体框架表达式来连接三个表,并在每个文档的一行中选择文档表和团队名称的所有字段。所以基本上我想加入三个表使用 group_concat 作为团队名称。然后我想将它绑定到 web 表单中的 gridview。
我尝试过的,
(from dc in DBContext.Document
join dr in DBContext.DocumentResponsible on dc.Id equals dr.DocumentId
join t in DBContext.Team on dr.TeamId equals t.Id
select new
{
Name = dc.Name,
Type = dc.Type,
Application = dc.Application,
Pcda = dc.Pcda,
}).ToList();
我刚刚试过了,
var data = DBContext.Dcoument.Include("DocumentResponsibles").Tolist();
【问题讨论】:
-
“DcoumentResponsibles”应该这样拼写吗?它似乎不符合您的其余命名。
-
谢谢,我打错了。
标签: c# asp.net entity-framework webforms