Model代码:
public partial class V_FirmBasisPro { public int FbID { get; set; } public string FbName { get; set; } public Nullable<int> FbProvinceID { get; set; } public Nullable<int> FbCityID { get; set; } public string FbStreet { get; set; } public string ProID { get; set; } public string ProName { get; set; } public Nullable<int> PRoProvinceID { get; set; } public Nullable<int> ProCityID { get; set; } public string ProStreet { get; set; } public Nullable<int> ProType { get; set; } public Nullable<System.DateTime> ProStateTime { get; set; } public Nullable<System.DateTime> ProEndTime { get; set; } public Nullable<int> ProStatus { get; set; } public string Creater { get; set; } public Nullable<System.DateTime> CreateDate { get; set; } public string Updater { get; set; } public Nullable<System.DateTime> UpdateDate { get; set; } }
Mapping代码:
public class V_FirmBasisProMap : EntityTypeConfiguration<V_FirmBasisPro> { public V_FirmBasisProMap() { // Primary Key this.HasKey(t => new { t.FbID, t.ProID }); // Properties this.Property(t => t.FbID) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(t => t.FbName) .HasMaxLength(200); this.Property(t => t.FbStreet) .HasMaxLength(200); this.Property(t => t.ProID) .IsRequired() .HasMaxLength(50); this.Property(t => t.ProName) .HasMaxLength(200); this.Property(t => t.ProStreet) .HasMaxLength(200); this.Property(t => t.Creater) .HasMaxLength(100); this.Property(t => t.Updater) .HasMaxLength(100); // Table & Column Mappings this.ToTable("V_FirmBasisPro"); this.Property(t => t.FbID).HasColumnName("FbID"); this.Property(t => t.FbName).HasColumnName("FbName"); this.Property(t => t.FbProvinceID).HasColumnName("FbProvinceID"); this.Property(t => t.FbCityID).HasColumnName("FbCityID"); this.Property(t => t.FbStreet).HasColumnName("FbStreet"); this.Property(t => t.ProID).HasColumnName("ProID"); this.Property(t => t.ProName).HasColumnName("ProName"); this.Property(t => t.PRoProvinceID).HasColumnName("PRoProvinceID"); this.Property(t => t.ProCityID).HasColumnName("ProCityID"); this.Property(t => t.ProStreet).HasColumnName("ProStreet"); this.Property(t => t.ProType).HasColumnName("ProType"); this.Property(t => t.ProStateTime).HasColumnName("ProStateTime"); this.Property(t => t.ProEndTime).HasColumnName("ProEndTime"); this.Property(t => t.ProStatus).HasColumnName("ProStatus"); this.Property(t => t.Creater).HasColumnName("Creater"); this.Property(t => t.CreateDate).HasColumnName("CreateDate"); this.Property(t => t.Updater).HasColumnName("Updater"); this.Property(t => t.UpdateDate).HasColumnName("UpdateDate"); } }
DbContent代码:
public DbSet<V_FirmBasisPro> V_FirmBasisPro { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new V_FirmBasisProMap()); }
这样的代码 会创建视图还是创建表 ,总感觉会创建表。
是否Ef6.0只能通过code first创建表,视图和存储过程需要去数据库中通过管理器创建?
这种方式创建的是表,视图和存储过程可以写脚本在DB初始化的时候通过SQL创建