I have class like this:
public class Target
{
[Key]
[Column("TargetId")]
public Guid Id { get; set; }
[ForeignKey("TargetInventory")]
public Guid? TargetInventoryId { get; set; }
public virtual TargetInventory TargetInventory { get; set; }
}
On DbContext only this:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove();
}
On database I have FK named 'FK_Target_TargetInventory' and field 'TargetInventoryId'.
With EF 4 it worked but on 4.1 it generates invalid field name 'TargetInventory_Id' instead of 'TargetInventoryId'. Exception:
Load operation failed for query 'GetAll'. An error occurred while executing the command definition. See the inner exception for details. Inner exception message: Invalid column name 'TargetInventory_Id'.
What could be wrong?
Edit 1
Code tag is not rendering well (I think you can understand what it means): modelBuilder.Conventions.Remove<<'IncludeMetadataConvention'>>(); I havent used fluent before and it worked, I don't want to have logic outside main class. Now I will try various tests as I found similiar code working in different class.