Data Annotation Feature-Column, Annotation Feature-column
The Column feature can be used in class attributes. The default convention of Code-First is to use the attribute name as the Column name. This Column feature can break this feature.
See the following code:
using System;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;using System.Linq;using System.Text;using System.Threading.Tasks;namespace EF2{ [Table("StudentMaster",Schema="WaHaHa")] public class Student { [Key] [Column(Order=1)] public int StudentKey1 { get; set; } [Key] [Column(Order=2)] public int StudentKey2 { get; set; } [MaxLength(20)] [ConcurrencyCheck] [Required] public string StudentName { get; set; } [NotMapped()] public int? Age { get; set; } [Column("StandardID")] public int StdId { get; set; } [ForeignKey("StdId")] public virtual Standard Standard { get; set; } }}
Of course, you can also specify the Order and Type of columns. See:
using System;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;using System.Linq;using System.Text;using System.Threading.Tasks;namespace EF2{ [Table("StudentMaster",Schema="WaHaHa")] public class Student { [Key] [Column(Order=1)] public int StudentKey1 { get; set; } [Key] [Column(Order=2)] public int StudentKey2 { get; set; } [MaxLength(20)] [ConcurrencyCheck] [Required] [Column("SName",Order=4,TypeName="varchar")] public string StudentName { get; set; } [NotMapped()] public int? Age { get; set; } [Column("StandardID",Order=3,TypeName="int")] public int StdId { get; set; } [ForeignKey("StdId")] public virtual Standard Standard { get; set; } }}