Hello guys I have a problem with migraiton.I use abstract class like:
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; }
[ForeignKey("UserId")]
public int UserId { get; set; }
public DateTime? DateTime { get; set; }
public virtual User User { get; set; }
Then I have 2 tables like as follows:
public class MovieFavoriteList:FavoriteListBase<int>
{
public List<int> MovieIds { get; set; }
}
public class TvSeriesFavoriteList:FavoriteListBase<int>
{
public List<int> TvIds { get; set; }
}
When I try to migrate this error occurs:
The entity type 'List<int>' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943 .
Do you guys have an idea about how can I fix it?
I try as follows:
[Keyless]
public class TvSeriesFavoriteList:FavoriteListBase<int>
{
public List<int> TvIds { get; set; }
}
however then I realized it was nonsense:
[ForeignKey(nameof(MovieIds)]
public int MovieIds {get;set;}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<MovieFavoriteList>().HasKey(p=>p.MovieIds)
}
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.