简体   繁体   中英

The seed identity for entity type 'sponsor cannot be found

I am trying to load Sponsors from an Azure database, but I am getting this error. The table has a column sponsorid and the Class Sponsors also has an sponsorid property;

System.InvalidOperationException: 'The seed entity for entity type 'Sponsor' cannot be added because there was no value provided for the required property 'SponsorID'.'

public async Task<ActionResult<IEnumerable<Sponsor>>> GetSponsor()
        {
            return await _context.Sponsors.ToListAsync();
        }

Where does this error come from?

The code uses seed data and the seed data is missing the column SponsorId . Search for similar code to the following in your DbContext in OnModelCreating method and supply the value of the primary key:

modelBuilder.Entity<Sponsor>().HasData(new []{
    new Sponsor {
        ... // add SponsorId here
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM