I'm trying to connect two tables by means of code in C# with Entity Framework Core.
The classes are:
public class roll
{
[key]
public int rollId { get; set; }
public List<pieces> pieces { get; set; }
}
public class pieces
{
[Key]
public int pieceId { get; set; }
public int quantity { get; set; }
public decimal price { get; set; }
}
In my DbContext, I have the following method:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<roll>()
.HasRequired(m => m.quantity)
.WithMany(m => m.pieces)
.HasForeignKey(m => m.pieceId);
base.OnModelCreating(modelBuilder);
}
HasRequired turns red and gives this message:
EntityTypeBuilder does not contain a definition for HasRequired.
The project has added a reference to Microsoft.EntityFrameworkCore.Relational.
I have recompiled the solution, closed and opened visual studio and I cannot solve that HasRequired stops being red
What is wrong with my code?