我正在使用Entity Framework 6.0.2和Oracle 11g。
我正在尝试使用实体框架添加,更新和删除对象。
我没有获得SaveChanges(),Remove(),Add()方法的智能感知。
获取这些内容需要哪些参考资料。 我在packages.config中添加了以下内容。 这是我的package.Config。
<packages>
<package id="EntityFramework" version="6.0.2" targetFramework="net45" />
<package id="odp.net.x64" version="112.3.20" targetFramework="net45" />
<package id="Oracle.DataAccess.x86" version="2.112.1.0" targetFramework="net45" />
<package id="Oracle.ManagedDataAccess" version="12.1.021" targetFramework="net45" />
<package id="Oracle.ManagedDataAccess.EntityFramework" version="12.1.021" targetFramework="net45" />
</packages>
这是我的DbContext。
public class OLADBContext:DbContext,IOLADBContext
{
protected static string m_connectionString = "";
public static OLADBContext Create()
{
ConnectionStringSettings dbSettings = ConfigurationManager.ConnectionStrings["OracleDbContext"];
if (dbSettings != null)
{
m_connectionString = dbSettings.ConnectionString;
}
return new OLADBContext(m_connectionString);
}
public OLADBContext(string connectionString)
: base(connectionString)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("HRMS2");
modelBuilder.Configurations.Add(new EmployeeMapper());
modelBuilder.Configurations.Add(new EmpAuthMapper());
modelBuilder.Configurations.Add(new SpecialPrivilegesMapper());
modelBuilder.Configurations.Add(new ProbationDetailsMapper());
base.OnModelCreating(modelBuilder);
}
public DbSet<Employee> Employes { get; set; }
public DbSet<EmpAuthentication> Authentication { get; set; }
public DbSet<SpecialPrivileges> SpecialPrivilege { get; set; }
public DbSet<ProbationDetails> ProbationDetails { get; set; }
}
这是我的代码:
public void CheckEmployeeExists(string EmpId)
{
var userType="N";
var authenticationDetails = _olaDbContext.Authentication.Where(a => a.IsEnabled == "Y" && a.EmployeeId == EmpId).FirstOrDefault();
if (authenticationDetails == null)
{
var emp = _olaDbContext.Employes.Where(e=>e.EmployeeId==EmpId).FirstOrDefault();
if (emp != null)
{
if (emp.IsManager == "Y")
userType = "T";
else if (emp.Designation.ToUpper().Contains("HR EXEC") || emp.Designation_Id == 447)
{
userType = "H";
}
else if (emp.Designation.Contains("Time Office"))
{
userType = "A";
}
var probationDetails = _olaDbContext.ProbationDetails.Where(p => p.EmployeeId == EmpId);
ProbationDetails oprob = new ProbationDetails();
oprob.EmployeeId = "16785";
oprob.ProbatoionPeriod = 3;
_olaDbContext.ProbationDetails.Add(oprob);
}
}
}
请让我知道我怎么能实现?
答案 0 :(得分:0)
我修好了。
我正在做错而不是直接引用OLADbConext我在我的类中引用了IOLADbContext
public class OLADBContext:DbContext,IOLADBContext
{
}
我评论了引用该接口的代码并直接使用了类
public class OLADataProvider:IOLADataProvider
{
// private IOLADBContext _olaDbContext;
private OLADBContext _olaDbContext;
public OLADataProvider(OLADBContext olaDbContext)
{
if (olaDbContext == null)
throw new ArgumentNullException("olaDbContext is Null");
//_olaDbContext = olaDbContext;
_olaDbContext = olaDbContext;
}