0

I seeded my data from from external Json file ,everything is correct but it shows the error that object reference not set an instance of an object.

DbContextClass:

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
    {
    }

    public DbSet<schemedemet> schemedemets { get; set; }

    public DbSet<schemedet> schemedets { get; set; }

    public  DbSet<schemephy> schemephys { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<schemedemet>().HasNoKey().HasData(seedAllDemet());
        modelBuilder.Entity<schemedet>().HasNoKey();
        modelBuilder.Entity<schemephy>().HasNoKey();
    }

    public List<schemedemet> seedAllDemet()
    {
        var datas = new List<schemedemet>();
        using (StreamReader r = new StreamReader(@"C:\Users\ADMIN\source\repos\Seed\Seed\Data\SeedData\schemedemat.json"))
        {
            string json = r.ReadToEnd();
            datas = JsonSerializer.Deserialize<List<schemedemet>>(json);
            return datas;
        }
    }
    ...
}

Peter Csala
  • 4,906
  • 7
  • 11
  • 29
  • What line of code is the error? Check this one: https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – Brad May 13 '21 at 12:23

0 Answers0