Skip to content

Instantly share code, notes, and snippets.

@ParmanBabra
Created May 25, 2019 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ParmanBabra/78114a17f1f225da5fb917a35d312bc1 to your computer and use it in GitHub Desktop.
Save ParmanBabra/78114a17f1f225da5fb917a35d312bc1 to your computer and use it in GitHub Desktop.
public class ShoppingContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Account>(builder =>
{
...
builder.HasOne(en => en.ShoppingCart) //ระบุความสัมพันธ์แบบ 1 ต่อ 1
.WithOne(en => en.Account)
.HasForeignKey<Account>(en => en.UserName); //ระบุ Property ที่เป็น FK
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment