Connect with Peer Bloggers

Get your Bloggers ID and network with best bloggers around the world.

10

How to declare foreign key in Entity Framework

Czetsuya
czetsuya's tech ― There are 2 ways to declare foreign key in entity framework. Assuming we have 2 entities aspnet_Users and Person, which are link via UserId from aspnet_Users.1.) class Person { public Guid UserId { get;set; } [ForeignKey("UserId")] public virtual AspnetUser AspnetUser { get; set; }}2.) [ForeignKey("AspnetUser")] public Guid UserId { get;set; } public virtual AspnetUser AspnetUser { get; set; }

Voted by 1 User



What would you say?

Be the first to comment on this blog post! Sign in or Create an account.