我有两张桌子
我正试图与这两个表(Fluent API)强制实现一对多的关系
public partial class PropertyListing
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public string StreetAddress { get; set; }
//the column that links with PropertyAvaibility table PK
public byte? Availability { get; set; }
public bool Status { get; set; }
public virtual PropertyAvailability PropertyAvailability { get; set; }
}
public partial class PropertyAvailability
{
public byte ID { get; set; }
public string Status { get; set; }
public virtual ICollection<PropertyListing> PropertyListings { get; set; }
public PropertyAvailability()
{
PropertyListings = new List<PropertyListing>();
}
}
我在OnModelCreating
modelBuilder.Entity<PropertyListing>()
.HasRequired(pl => pl.PropertyAvailability)
.WithMany(pa => pa.PropertyListings)
.HasForeignKey(pl => pl.Availability);
失败并出现此错误,
列名称无效&#39; PropertyListing_ID&#39;。
可能有什么不对?我知道我已经搞砸了EF6期望的命名惯例,但是还没有解决方法吗?
P.S:我在SO中已经看到这个问题来自ef3左右,但我无法找到任何解决方案,因此无法找到问题。答案 0 :(得分:1)
将Column属性添加到您的类
public partial class PropertyListing
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity), Column("ID")]
public int ID { get; set; }
public string StreetAddress { get; set; }
//the column that links with PropertyAvaibility table PK
public byte? Availability { get; set; }
public bool Status { get; set; }
public virtual PropertyAvailability PropertyAvailability { get; set; }
}