I'm working on one project where we use entity framework for database transaction. While making a database transaction, if there's any reference key in particular table, then it autogenerates new field for that referenced entity which doesn't even exist.
For Example:
I've one table called Stations which has a reference of StationTypes(one-to-one).
Now whenever we try to create/update any record in Stations table, it by defaylt inject one field called "StationType_Id" into particular query called "StationType_Id" - which is not even exist and end up in throwing bellow error.
Invalid column name 'StationTypes_Id'.
Sample DB entity generated by EF
public partial class Stations
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Stations()
{
this.OrganizationStations = new HashSet<OrganizationStations>();
}
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int StationTypeId { get; set; }
public int Status { get; set; }
public int CreatedBy { get; set; }
public System.DateTime CreatedDate { get; set; }
public Nullable<int> UpdatedBy { get; set; }
public Nullable<System.DateTime> UpdatedDate { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<OrganizationStations> OrganizationStations { get; set; }
public virtual StationTypes StationTypes { get; set; }
}
public virtual StationTypes StationTypes { get; set; }
navigation property. Do you have a FK column in the associated db table? Mapping one-to-one in EF6 has some issues, can you also post theStationTypes
class? Also you may need to look at the relationship properties in the EDMX designer. – Ivan Stoev Jun 23 '19 at 10:55