Categories
c# ef-fluent-api entity-framework entity-framework-core sql

SqlClient.SqlException: Invalid column name ClassNameId While fetching data from Fluent API

I am new to this EF,I am tring to fetch data from Sql Db table, and it gives me error like invalid classNameId error.

public class ClassName
{
[Key]
[Display(Name = "Id:")]
public int Id { get; set; }
[Display(Name = "Created By:")]
[Required(ErrorMessage = "Please enter created by.")]
[StringLength(5, MinimumLength = 2)]
public string CreatedBy { get; set; }
public List<OtherClass> OtherClassList{ get; set; }
}
public class OtherClass
{
[Column("Control")]
[Display(Name = "Control:")]
public String Control { get; set; }
[ForeignKey("PID")]
[Column("PID")]
[Display(Name = "PID:")]
public int PID{ get; set; }
}

DbContext:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ClassName>()
.HasKey(p => p.Id);
modelBuilder.Entity<OtherClass>()
.HasKey(p=> new { p.Control, p.PID});
}

I have use Fluent API for get data from MSSql.