c# - Mapping in Entity Framework -


i have existing db schema (cant change ..) . need ef mapping

student table:

id    name     courseid ------------------------  1    name1     100023  2    name2     100023  3    name3     100024    4    name4     null   

course table:

id   courseid   coursename --------------------------  1   100023      course1    2   100022      course2    3   100024      course3    4   100023      course1   

id primary key in both tables. courseid column relationships.

there no explicit relationship in database (sql server) also.

when try mapping in ef specifying courseid key required mapping throws error telling not defined key property. cannot add key property null-able field.

is there way mapping?

that's pretty rough schema work with. however, might able use composite key courses table. haven't tested it, should work.

public class course {     [key, column(order = 0)]     public int id { get; set; }      [key, column(order = 1)]     public int? courseid { get; set; }      public string coursename { get; set; } }  public class student {     [key]     public int id { get; set; }      public string name { get; set; }      public int? courseid { get; set; }      [foreignkey("courseid")]     public course course { get; set; } } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -