首页 新闻 搜索 专区 学院

EF Code frist 如何支持视图

0
悬赏园豆:20 [已解决问题] 解决于 2016-05-14 23:27

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创建表,视图和存储过程需要去数据库中通过管理器创建?

淡_- -的主页 淡_- - | 初学一级 | 园豆:34
提问于:2015-11-19 16:37
< >
分享
最佳答案
0

这种方式创建的是表,视图和存储过程可以写脚本在DB初始化的时候通过SQL创建

收获园豆:20
古月三石 | 菜鸟二级 |园豆:259 | 2015-11-24 16:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册