EF One-to-many不加载儿童收藏

时间:2014-03-11 19:35:32

标签: entity-framework ef-code-first

public partial class OrdemProducao
{
    public OrdemProducao()
    {
        this.Processos = new HashSet<OrdemProcesso>();
    }
    public string Filial { get; set; }
    public string NumeroOP { get; set; }
    public virtual ICollection<OrdemProcesso> Processos { get; set; }
}

public partial class OrdemProcesso
{
    public string Filial { get; set; }
    public string NumeroOP { get; set; }
    public double FaseSequencia { get; set; }
}

OrdemProducao - 配置

HasMany(x => x.Processos)
    .WithOptional()
    .HasForeignKey(x => new { x.Filial, x.NumeroOP })
    .WillCascadeOnDelete(false);

查询

var ord = _context.OrdemProducao.Include(x => x.Processos).Single(x => x.NumeroOP == "000001");
var cnt = ord.Processos.Count(); // <= is empty!!

它正确返回对象,但Processos属性没有任何项......

我在SQL Server中分析了生成的查询....它从两个连接表中返回数据..只在对象中没有返回....

0 个答案:

没有答案