I have created an entity class in my MVC 3 application. One of the attribute named RegistryId is primary key as well as foreign key. How can I make a column primary key as well as Foreign key ? I am not using EF ORM designer. I am coding classes by hand.
Share
I think by “not using EF ORM designer” you mean new
DbContextAPI from EF 4.1. Because if you don’t meanDbContextAPI you still have to use EDMX (designer).You can either use data annotations (
System.ComponentModel.DataAnnotations):KeyAttributeandForeignKeyAttribute:Or you can use fluent API (overriding
OnModelCreatingin your derived context):(Edit: fluent mapping was reversed and incomplete)
Where
MyEntityis your entity with FK andRegistryis principal entity in 1:1 relationship.