【发布时间】:2017-07-15 23:59:16
【问题描述】:
这是我的模型架构。
这是依赖实体
public class ArticleFee
{
public int ID { get; set; }
public string Description { get; set; }
public Type Type { get; set; }
public double? FixedFee { get; set; }
public int? RangeStart { get; set; }
public int? RangeEnd { get; set; }
public double? Percentage { get; set; }
[StringLengthAttribute(1, MinimumLength = 1)]
public string ArticleLetter { get; set; }
public Article Article { get; set; }
}
public class Article
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[KeyAttribute]
[StringLengthAttribute(1, MinimumLength = 1)]
public string Letter { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public ICollection<ArticleFee> ArticleFees { get; set; }
}
这是我在路线上显示数据的方式,但 ArticleFees 只显示一个空数组。
[HttpGetAttribute]
public IEnumerable<Article> Get()
{
return _context.Articles
.Include(a => a.ArticleFees)
.ToList();
}
【问题讨论】:
-
你的问题是?
-
我如何获取相关或依赖实体并在我的路线上显示它们?
-
反射(元数据)?
-
当您首先在局部变量中捕获查询结果并查看调试器时,
Include是否有效?这是哪个 ef-code 版本?
标签: asp.net asp.net-core entity-framework-core