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
public static bool IsOverlapped(string start1, string end1, string start2, string end2) | |
{ | |
CultureInfo enUS = new CultureInfo("en-US"); | |
DateTime dateStart1, dateEnd1, dateStart2, dateEnd2; | |
string dateFormat = "yyyymmdd"; | |
if (!DateTime.TryParseExact(start1, dateFormat, enUS, DateTimeStyles.None, out dateStart1)) | |
throw new ArgumentException(nameof(start1) + "is wrong format"); | |
if (!DateTime.TryParseExact(end1, dateFormat, enUS, DateTimeStyles.None, out dateEnd1)) |
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
public class CartItem | |
{ | |
public int ProductId { get; set; } | |
public string Username { get; set; } | |
public int Count { get; set; } | |
} |
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
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 |
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
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
... | |
modelBuilder.Entity<Product>(builder => // ระบุ Model ที่ต้องการ Map กับ Table | |
{ | |
... | |
builder.Property(en => en.Weight) | |
.HasColumnName("Weight") |
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
public class Product | |
{ | |
... | |
public float Weight { get; set; } | |
} |
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
public class Account | |
{ | |
public string UserName { get; set; } | |
public string Address { get; set; } | |
public string Title { get; set; } | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
} |
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) |
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
public class ShoppingContext : DbContext | |
{ | |
public DbSet<Product> Product { get; set; } | |
public DbSet<ShoppingCart> ShoppingCart { get; set; } | |
public DbSet<Account> Account { get; set; } | |
public DbSet<CartItem> CartItem { get; set; } |
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
public class ShoppingCart | |
{ | |
public string Username { get; set; } | |
} |
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
public class Product | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public float Price { get; set; } | |
} |