System.InvalidOperationException: 'Entity type '' is in shadow-state. A valid model requires all entity types to have corresponding CLR type.'

asp.net-core-webapi c# entity-framework-core

Question

I'm working on an ASP.NET Core web API project, but when I run my web application, I get this error:

System.InvalidOperationException: 'Entity type 'Vocabulary' is in shadow-state. A valid model requires all entity types to have corresponding CLR type.'

I'm using Entity Framework Core 2. The issue is with the GetAll method in the VocabularyManager class.

[Route("api/vocabulary")]
public class VocabularyController : ControllerBase
{
    [HttpGet()]
    public IActionResult GetAllVocabulary()
    {
        var vocab = _iRepo.GetAll();
        return new JsonResult(vocab)
        {
            StatusCode = 200
        };
    }
}

public class VocabularyManager : IDataRepository
{
    ApplicationContext ctx;
    public VocabularyManager(ApplicationContext c)
    {
        ctx = c;
    }

    public void Add(Vocabulary vocab)
    {
        ctx.Add(vocab);
        ctx.SaveChanges();
    }

    public void Delete(int id)
    {
        throw new NotImplementedException();
    }

    public Vocabulary Get(int id)
    {
        var vocabulary = ctx.Vocabularies.FirstOrDefault(c => c.Id == id);
        return vocabulary;
    }

    public IEnumerable<Vocabulary> GetAll()
    {
        var restVocab = ctx.Vocabularies.ToList();
        return restVocab;
    }

    public void Update(int id, Vocabulary vocab)
    {
        throw new NotImplementedException();
    }
}
1
0
1/17/2020 9:19:03 PM

Accepted Answer

Problem might be due to your were using wrong type for your entity in modelBuilder.Entity. You should use System.Type in the modelBuilder.Entity.

0
6/5/2018 11:46:20 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow