【问题标题】:Entity framework linq include实体框架 linq 包括
【发布时间】:2013-06-21 13:50:20
【问题描述】:

我正在使用实体框架进行以下 Linq 查询。

var res = from a in _db.Articles
                  from auth in a.Authors
                  where papers.Contains(a.JoomlaId)
                  select auth.Institution;

问题是我的机构类有一个名为“Type”的变量,类型为“InstitutionType”,我需要包含该变量,但我不知道该怎么做。

【问题讨论】:

  • 不要把你的变量称为“类型”,你未来的自己会杀了你
  • 你说得有道理,我不否认,但如果我称它为机构类型,它会像 Institution.InstitutionType 一样也不好。
  • 关联类型?我会尝试程序员交流,但是机构类型对我来说听起来不错,听起来不像是静态类型

标签: c# mysql asp.net-mvc entity-framework


【解决方案1】:
var res = from a in _db.Articles.Include("Authors") 
                                .Include("Authors.Institution")
                                .Include("Authors.Institution.Type")
                  from auth in a.Authors
                  where papers.Contains(a.JoomlaId)
                  select auth.Institution;

【讨论】:

  • 应该是var res = from a in _db.Articles .Include("Authors") .Include("Authors.Institution") .Include("Authors.Institution.Type") from auth in a.Authors where papers.Contains(a.JoomlaId) select auth.Institution; 可以编辑一下,以便我可以将其标记为答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
  • 1970-01-01
  • 2022-07-12
相关资源
最近更新 更多