ASP.NET MVC

Fluent API Basic

Source: Mosh Hamedani 1. Table Name modelBuilder.Entity().Totable(“tbl_Course”); 2. Table Name and Schema modelBuilder.Entity().Totable(“tbl_Course”,”schema”); 3. Primary Keys modelBuilder.Entity().HasKey(t => t.ISBN); 4. Composite Keys modelBuilder.Entity().HasKey(t => new {t.OrderId, t.OrderItemId}); 5. Column Name modelBuilder.Entity() .Property(t => t.Name) .HasColumn(“sName”); 6. Column Type modelBuilder.Entity() .Property(t => t.Name) .HasColumnType(“varchar”); 7. Column Orders modelBuilder.Entity() .Property(t => t.Name) .HasColumnOrder(2); 8. Database Generated modelBuilder.Entity()… Continue reading Fluent API Basic

ASP.NET MVC

Data Annotation Entity Framework

Source: Mosh Hamedani 1. Table Name [Table(“tbl_Course”, Schema = “”)] public class Course 2. Column Names [Column(“sName”, TypeName=”varchar”)] public string Name {get; set;} 3. Primary Key [Key] DatabaseGenerated(DatabaseGeneratedOption.None)] public string ISBN {get; set;} Lưu ý: DatabaseGeneratedOption có 3 thuộc tính: None, Identity và Computed 4. Composite Keys public class OrderItem { [Key] [Column(Order=1)] public int OrderId… Continue reading Data Annotation Entity Framework