我有一个问题,脚手架我的模型。 我得到以下错误“对象引用未设置为对象的实例”
我的模特:
public class Position
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long PositionID { get; set; }
public long OfferID { get; set; }
[Required]
[Display(Name = "Positie omschrijving")]
public string Name { get; set; }
[Required]
public int PositionNr { get; set; }
[Required]
public double WorkingHeight { get; set; }
public long PalletTypeID { get; set; }
public long MotorTypeID { get; set; }
public long Enveriment { get; set; }
}
我的DBContext:
public class FlowContext : DbContext
{
public DbSet<Position> Positions { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
this.Configuration.LazyLoadingEnabled = true;
//Positie
modelBuilder.Entity<Position>()
.HasKey(j => j.PositionID);
}
}
我在web.config中的连接字符串
<connectionStrings>
<add name="FlowContext" connectionString="data source=.\SqlExpress; Integrated Security=True;Initial Catalog=Flow;" providerName="System.Data.SqlClient" />