当前位置:Gxlcms > 数据库问题 > VS2015 ASP.NET MVC5 EntityFramework6 Oracle 环境篇

VS2015 ASP.NET MVC5 EntityFramework6 Oracle 环境篇

时间:2021-07-01 10:21:17 帮助过:32人阅读

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MvcOracle.Models
{
    public class OracleDbContext : DbContext
    {
        private readonly static string Connection_String = "name=OracleDbContext";
        public OracleDbContext()
            : base(Connection_String)
        {
            Database.SetInitializer<OracleDbContext>(new CreateDatabaseIfNotExists<OracleDbContext>());
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.HasDefaultSchema("LYDXHF");//LYDXHF为数据库用户名
     }

     public DbSet<GG_ZTXXB> listGG_ZTXXB { get; set; }//GG_ZTXXB为数据表实体类
  } 
}
技术图片

如果不指定数据库用户名,EF会自动默认访问dbo用户,导致数据访问失败。

 

VS2015 ASP.NET MVC5 EntityFramework6 Oracle 环境篇

标签:set   ali   microsoft   initial   tin   nec   环境配置   各版本   自定义   

人气教程排行