Answer the question
In order to leave comments, you need to log in
ENTITY FRAMEWORK Fluent API how to prevent creating a record if it already exists?
There are 2 tables with many to many relationship
public class Movie
{
[Key]
public int MovieId{ get; set; }
[MaxLength(100)]
public string Title{ get; set; }
public List<Country> Countrys{ get; set; }
}
public class Country
{
[Key]
public int CountryId { get; set; }
[MaxLength(10)]
public string Key { get; set; }
public List<Movie> Movies { get; set; }
}
modelBuilder.Entity<Cinema_Country>()
.HasMany(c => c.Movies)
.WithMany(c => c.Countrys)
.Map(c =>
{
c.ToTable("Cinema_CountryMovie");
c.MapRightKey("MovieId");
c.MapLeftKey("CountryId");
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question