Add Multiple Foreign Key for the Same table in MVC Database First SQL, multiple Foreign Key for the Same table in Entity Framework, thêm nhiều khóa ngoại giống nhau của 1 bảng vào 1 bảng table dữ liệu sử dụng mô hình Database First. Thêm 2 khóa ngoại giống nhau của 1 table vào table trong sql server. Mình có 2 bảng table Citys và Products trong sql server như hình sau: Có 2 cột khóa ngoại của bảng Products liên kết qua bảng Citys là: CityId và CityBormId. Để tạo khóa ngoại cho 2 cột này bạn click chuột phải vào chọn: Relationships... như hình dưới. Tiếp theo bạn chọn Add, sau đó click vào dữ liệu vừa add ở tab Tables And Columns Specific bạn click chọn và điền khóa ngoại giống hình dưới. Trong code MVC asp.net C# tại Model City.cs của bạn đã có sẵn bạn điền thêm InverseProperty để truy xuất dữ liệu liên kết như sau: City.cs Mã: //Trong model City.cs // Citys public partial class City { public int Id { get; set; } public string CityName { get; set; } public string ZipCode { get; set; } public string Note { get; set; } [InverseProperty("City")] public virtual ICollection<Product> CityId { get; set; } [InverseProperty("CityBorn")] public virtual ICollection<Product> CityBornId { get; set; } } Product.cs Mã: //Trong model Product.cs // Products public partial class Product { public int Id { get; set; } public string Name { get; set; } public string NameShort { get; set; } public string URLName { get; set; } public Nullable<int> CityId { get; set; } public Nullable<int> CityBornId { get; set; } //add 2 khóa ngoại liên tiếp vào bảng city public virtual City City { get; set; } public virtual City CityBorn { get; set; } } Vậy là xong bạn chạy thử ngay nhé. Ngoài ra các bạn có thể xem chi tiết đầy đủ các trường hợp ở link sau: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/data-annotations#Relationships