entity framework - ASP.NET MVC are two foreign fields in dependent class of One to Many relationship legal -


i have problem relationships in asp.net mvc. have 2 models have 1 many relationship. on dependent class), other class has 2 fields. know dependent class applies foreign attribute establish relationship. in dependent class, unsure if should use foreignkey attributes point other class. per this tutorial on mvc site

here simplified example of problem.

public class location {     //other fields here.     public list<link> links{get; set;} }  // dependent class public class link {     //other fields here...      [foreignkey("location")]     public string startinglocation { get; set;}      [foreignkey("location")]     public string endinglocation { get; set;}      public location location  { get; set;} } 

is doing on dependent class legal , if recommended?

thanks , regards.

if link entity going have 2 foreign keys pointing same parent, need 2 navigational properties , use inverseproperty attribute tell ef belongs which. https://msdn.microsoft.com/en-us/data/jj591583.aspx#relationships

// dependent class public class link {     //other fields here...       public string startinglocation { get; set;}      public string endinglocation { get; set;}       [inverseproperty("startinglocation")]      public location startloc  { get; set;}       [inverseproperty("endinglocation")]      public location endloc  { get; set;}  } 

this assumes startinglocation , endinglocation foreign keys , have used fluent api configure them such since not following "id" convention.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -