Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Created Unassigned: Foreign Key Not Mapped Correctly [1106]

$
0
0
If I have the following code generating my database it assigns a foreign key from the TankComponent table to the Asset table instead of the Tank table. Can someone explain why? Do I need to turn of a specific convention or change in the Fluent API? Is it really only looking at the column name?

[Table("Asset")]
public abstract class Asset
{
[Key]
public int AssetId { get; set; }

public string Name { get; set; }

public string Description { get; set; }
}


[Table("Tank")]
public class Tank : Asset
{
public Tank()
{
this.TankCompnents = new Collection<TankComponent>();
}

public int TankField1 { get; set; }

public ICollection<TankComponent> TankCompnents { get; set; }

[NotMapped]
public IEnumerable<Floor> Floors { get { return this.TankCompnents.OfType<Floor>(); } }
}


[Table("TankComponent")]
public abstract class TankComponent
{
[Key]
public int TankComponentId { get; set; }

[ForeignKey("Tank")]
public int AssetId { get; set; }
public Tank Tank { get; set; }

public string Name { get; set; }
}


Viewing all articles
Browse latest Browse all 10318

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>