c# - Explicitly declare the column name for a navigation property -


i'm trying use entity framework 6.1.3 oracle 12c database server. have been warned. i'm not yet ready tell customer it's impossible. have put number of hacks in place. need one. generated column names can longer 30 characters oracle still unable handle those. thought use columnattribute properties it's ignored navigation properties.

here's sample code:

public class component {     public int componentid { get; set; }     [column("parentif")]     public virtual interface parentinterface { get; set; } } public class interface {     public int interfaceid { get; set; } } 

the generated name "parentinterface_interfaceid". want change shorter "parentif". above code not work, still uses longer name.

some code i've found elsewhere uses this:

protected override void onmodelcreating(dbmodelbuilder modelbuilder) {     // fix reference column names support oracle's 30 characters restriction.     // entity framework ignores column attribute on reference columns.     modelbuilder.entity<component>()         .map(m => m.mapkey("parentif"));      base.onmodelcreating(modelbuilder); } 

but incomplete. it's lacking specification column should mapped this. can't find missing pieces. , doesn't compile.

another idea using following:

modelbuilder.entity<component>()     .property(c => c.parentinterface)     .hascolumnname("parentif"); 

this gives me compiler error cs0453 don't understand.

is there way explicitly define column name must used reference property in entity framework code first?

the easiest way add property model interface id:

public int parentinterfaceid { get; set; } 

now can control column name column attribute:

[column("parentif")] public int parentinterfaceid { get; set; } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -