EF Core访问嵌套嵌套实体

时间:2017-06-23 14:32:39

标签: database entity-framework asp.net-core data-access-layer

我有一个实体CallTrackerLog,其中有许多Clients,其中有一个Advices。我正在尝试为advice

创建HttpPost创建
    [HttpPost("{callTrackerId}/{clientId}/advice")]
    public IActionResult CreateCTClientAdvice(int callTrackerId, int clientId,
        [FromBody] CallTrackerClientAdvice newAdvice)
    {
        if (newAdvice == null)
            return BadRequest();

        if (!ModelState.IsValid)
            return BadRequest(ModelState);

        var ctFromStore = _context.CallTrackers
            .Include(log => log.CallTrackerClients)
                .ThenInclude(log => log.CallTrackerClientAdvice)
            .FirstOrDefault(ct => ct.CallTrackerId == callTrackerId);

        var ctAdviceFromStore ctFromStore.CallTrackerClients.CallTrackerClientAdvice
            .FirstOrDefault(c => c.CallTrackerClientId == clientId);

        // ... add to db

        return Ok();
    }

问题是我无法使用CallTrackerClientAdvice访问.FirstOrDefault(ct => ct.CallTrackerClientId == clientId) - 它给了我一个红色下划线,即使我认为我已将其加载到上面。

错误:

enter image description here

为什么我无法访问CallTrackerClientAdvice

1 个答案:

答案 0 :(得分:1)

我怀疑你想要的是:

"2014-03"