In Entity Framework 4.1, foreign keys are generated in the following ways:
1-if the navigation attribute is specified, a foreign key is automatically generated. The naming rule is "Table name_primary key name"
2-by default, fields with the same primary key name as the navigation property are automatically marked as foreign keys,
3-use [foreignkey] to mark the attribute of the specified object class as a foreign key,
4-upgrade Mode 2. fields with the same primary key name as the navigation attribute are automatically marked as foreign keys, and then the column names in the database corresponding to the field are specified.
Method 3 and 4 specify the names of columns in the generated database.
View code
Public Class User { Public Int Userid { Get ; Set ;} Public String Name { Get ; Set ;} Public String Email { Get ; Set ;}} Public Class Userextinfo { Public Int Userextinfoid { Get ; Set ;} // 1-generate a foreign key: user_userid Public Virtual User user { Get ; Set ;} // 2-generate a foreign key: userid Public Int Userid { Get ; Set ;} Public Virtual User user { Get ; Set ;} // 3-generate a foreign key: f_userid Public Int F_userid { Get ; Set ;} [Foreignkey ( " F_userid " )] Public Virtual User user { Get ; Set ;} // 4-generate a foreign key: f_userid [Column ( " F_userid " )] Public Int Userid { Get ;Set ;} Public Virtual User user { Get ; Set ;}}