我正在使用EF6.1.3。我有3个poco的pickbatch,order,orderline。
public class PickBatch
{
public int Id { get; set; }
public string Barcode { get; set; }
public byte Status { get; set; }
public string Picker { get; set; }
public DateTime DateCreated { get; set; }
public DateTime? DateModified { get; set; }
public List<Order> Orders { get; set; }
}
public class Boxes
{
public Order()
{
OrderLines = new List<OrderLines>();
}
public int Id { get; set; }
public int? PickBatchId { get; set; }
public string OrderType { get; set; }
public string OrderNumber { get; set; }
public string CustomerNumber { get; set; }
public byte Status { get; set; }
public DateTime DateCreated { get; set; }
public DateTime? DateModified { get; set; }
public List<OrderLine> OrderLines { get; set; }
}
public class OrderLines
{
public int Id { get; set; }
public string Article { get; set; }
public string ArticleDescription { get; set; }
public int QtyOrdered { get; set; }
public int QtyDelivered { get; set; }
public int OrderId { get; set; }
public byte Status { get; set; }
public string Picker { get; set; }
public string PickLocation { get; set; }
public string Sorting { get; set; }
public DateTime DateCreated { get; set; }
public DateTime? DateModified { get; set; }
}
并非所有属性都与表中的列名匹配。所以在模型创建上我正在解决这个问题。
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<PickBatch>().ToTable("PickBatch");
modelBuilder.Entity<PickBatch>().HasKey(b => b.Id);
modelBuilder.Entity<PickBatch>().Property(b => b.Id).HasColumnName("PickBatchId");
modelBuilder.Entity<Order>().HasKey(b => b.Id);
modelBuilder.Entity<Order>().Property(b => b.Id).HasColumnName("OrderId");
modelBuilder.Entity<OrderLine>().HasKey(b => b.Id);
modelBuilder.Entity<OrderLine>().Property(o => .Id).HasColumnName("OrderLineId");
}
检索订单时,我得到一个execption:无效的列名'PickBatch_Id'。我不明白为什么EF想要添加这个属性?