c# - Invalid column name TableName_ID error -


i have 2 tables

  1. propertylisting - stores details of property user add, fk
  2. propertyavailability - it's table stores property status ( available, after 3 months, ...)

i trying enforce one-to-many relation these 2 tables (fluent api) this

public partial class propertylisting {     [key, databasegenerated(databasegeneratedoption.identity)]     public int id { get; set; }     public string streetaddress { get; set; }     //the column links 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>();     } } 

i calling on onmodelcreating

modelbuilder.entity<propertylisting>()         .hasrequired(pl => pl.propertyavailability)         .withmany(pa => pa.propertylistings)         .hasforeignkey(pl => pl.availability); 

it fails error,

invalid column name 'propertylisting_id'.

tutorial used: http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx

what wrong? know have screwed naming convention ef6 expects, isn't there workaround?

p.s: have seen question asked ef3 or in our so, unable find solution , hence question.

add column attribute class

public partial class propertylisting {     [key, databasegenerated(databasegeneratedoption.identity), column("id")]     public int id { get; set; }     public string streetaddress { get; set; }     //the column links propertyavaibility table pk     public byte? availability { get; set; }      public bool status { get; set; }      public virtual propertyavailability propertyavailability { get; set; } } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -