然后包含收藏不包含我的收藏数据

时间:2019-05-15 05:56:14

标签: asp.net-core entity-framework-core

我现在正在使用EF Core 2.1加载数据,并且在include数据中有一个集合。

我尝试了AsEnumerableToAsyncEmumerable,但是没有用。 balanceQuestion处显示的断点是count = 0

public class OutcomeMeasurementTools
{
    [Key] public int OutcomeMeasurementToolsId { get; set; }

    public bool IsWound { get; set; }
    public bool IsPediatrics { get; set; }
    public bool IsPelvic { get; set; }
    public bool IsVestibular { get; set; }
    public bool IsUpperExtremity { get; set; }
    public bool IsSpine { get; set; }
    public bool IsLowerExtremity { get; set; }
    public bool IsBalance { get; set; }
    public bool IsPain { get; set; }
    public bool IsGeneralFunction { get; set; }

    public ProgressNoteObjective ProgressNoteObjective { get; set; }
    public int ProgressNoteObjectiveId { get; set; }

    public Balance Balance { get; set; }

}

public class Balance
{
    [Key] public int BalanceId { get; set; }

    public double? Score { get; set; }

    public bool IsABCScale { get; set; }
    public bool IsBerg { get; set; }
    public bool IsFAB { get; set; } // Fullerton Advanced Balance (FAB) Scale
    public bool IsMSS { get; set; } // Motion Sensitivity Score *
    public bool IsTinetti { get; set; }
    public bool IsMCTSIB { get; set; } // *

    public ICollection<BalanceQuestions> BalanceQuestions { get; set; } // this return count 0 but i have my data in db
    public MSS MSS { get; set; }
    public MCTSIB MCTSIB { get; set; }

    public OutcomeMeasurementTools OutcomeMeasurementTools { get; set; }
    public int OutcomeMeasurementToolsId { get; set; }
}

public class BalanceQuestions
{
    [Key] public int BalanceQuestionId { get; set; }

    public int? Score { get; set; }

    // Identifier
    public bool IsABCScale { get; set; }
    public bool IsBerg { get; set; }
    public bool IsFAB { get; set; } // Fullerton Advanced Balance (FAB) Scale
    public bool IsTinetti { get; set; }

    public int? Q1 { get; set; }
    public int? Q2 { get; set; }
    public int? Q3 { get; set; }
    public int? Q4 { get; set; }
    public int? Q5 { get; set; }
    public int? Q6 { get; set; }
    public int? Q7 { get; set; }
    public int? Q8 { get; set; }
    public int? Q9 { get; set; }
    public int? Q10 { get; set; }
    public int? Q11 { get; set; }
    public int? Q12 { get; set; }
    public int? Q13 { get; set; }
    public int? Q14 { get; set; }
    public int? Q15 { get; set; }


    public Balance Balance { get; set; }
    public int BalanceId { get; set; }
}

public async Task<OutcomeMeasurementTools> GetOutcomeMeasurementTools(int progressNoteObjectiveId)
{
    return await progressNoteRepo.GetOutcomeMeasurementTools(progressNoteObjectiveId)
            .Include(x => x.Balance)
                .ThenInclude(x => x.BalanceQuestions)
            .Include(x => x.Balance)
                .ThenInclude(x => x.MCTSIB)
                    .ThenInclude(x => x.C1)
            .Include(x => x.Balance)
                .ThenInclude(x => x.MCTSIB)
                    .ThenInclude(x => x.C2)
            .Include(x => x.Balance)
                .ThenInclude(x => x.MCTSIB)
                    .ThenInclude(x => x.C3)
            .Include(x => x.Balance)
                .ThenInclude(x => x.MCTSIB)
                    .ThenInclude(x => x.C4)
            .Include(x => x.Balance)
                .ThenInclude(x => x.MSS).SingleOrDefaultAsync();

}

1 个答案:

答案 0 :(得分:0)

我以前遇到过此问题,解决方法是再次Dim o As Object For Each o In MyCollection If TypeOf o Is IString Then Dim s As IString Set s = o 'cast to IString interface Debug.Print s.ToString Else Debug.Print TypeName(o) End If Next 父母:

Include

请注意,Intelisense无法用于辅助包含! 参考:https://github.com/aspnet/EntityFrameworkCore/issues/4716