Last active
May 25, 2019 19:37
-
-
Save ParmanBabra/29ef83a02d4835dc29ce43484d772cfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modelBuilder.Entity<Product>(builder => // ระบุ Model ที่ต้องการ Map กับ Table | |
{ | |
builder.ToTable("Products") //ระบุ ชื่อ Table ของ Model นี้ | |
.HasKey(en => en.Id); // ระบุ PK ของ Table นี้ | |
builder.Property(en => en.Name) //Property ของ Table | |
.HasColumnName("Name") //ระบุ ชื่อ Column ของ Property นี้ | |
.HasColumnType<string>("nvarchar(250)"); //ระบุ type ของ Column นี้ | |
builder.Property(en => en.Price) | |
.HasColumnName("Price") | |
.HasColumnType<float>("decimal(8, 2)"); | |
}); | |
modelBuilder.Entity<ShoppingCart>(builder => | |
{ | |
builder.ToTable("ShoppingCarts") | |
.HasKey(en => en.Username); | |
}); | |
modelBuilder.Entity<Account>(builder => | |
{ | |
builder.ToTable("Accounts") | |
.HasKey(en => en.UserName); | |
builder.Property(en => en.Address) | |
.HasColumnName("Address") | |
.HasColumnType<string>("nvarchar(MAX)"); | |
builder.Property(en => en.FirstName) | |
.HasColumnName("FirstName") | |
.HasColumnType<string>("nvarchar(250)"); | |
builder.Property(en => en.LastName) | |
.HasColumnName("LastName") | |
.HasColumnType<string>("nvarchar(250)"); | |
builder.Property(en => en.Title) | |
.HasColumnName("Title") | |
.HasColumnType<string>("nvarchar(50)"); | |
}); | |
modelBuilder.Entity<CartItem>(builder => | |
{ | |
builder.ToTable("CartItems") | |
.HasKey(en => new { en.ProductId, en.Username }); | |
builder.Property(en => en.Count) | |
.HasColumnName("Count") | |
.HasColumnType<int>("int"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment