Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF代码首先不使用npgsql创建表_C#_Entity Framework_Npgsql - Fatal编程技术网

C# EF代码首先不使用npgsql创建表

C# EF代码首先不使用npgsql创建表,c#,entity-framework,npgsql,C#,Entity Framework,Npgsql,我首先在Npgsql中使用EF代码。在我尝试使用contextclassObj保存更改之前,一切都很好 public class EmployeeRepository { private ESAppraisalcontext DBAccessObj = null; public EmployeeRepository() { DBAccessObj = new ESAppraisalcontext(); DBAccessObj.Employe

我首先在Npgsql中使用EF代码。在我尝试使用contextclassObj保存更改之前,一切都很好

public class EmployeeRepository
{
    private ESAppraisalcontext DBAccessObj = null;
    public EmployeeRepository()
    {
        DBAccessObj = new ESAppraisalcontext();
        DBAccessObj.Employees.Add(new Employee { EmployeeCode = "1", EmployeeName = "shuk" });
        DBAccessObj.SaveChanges();            
    }
}  
此时,
SaveChanges()
给出了一个异常,即关系\ESTables.Employee\不存在。下面是我的上下文类:

public class ESAppraisalcontext : DbContext
{
    public DbSet<Entity> Entities { get; set; }
    public DbSet<Employee> Employees { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.HasDefaultSchema("ESTables");
            base.OnModelCreating(modelBuilder);
    }
}
public class Employee 
{
    [Key]
    public string EmployeeCode { get; set; }
    public string EmployeeName { get; set; }
    public string EmailId { get; set; }
    public string DomainName { get; set; }
    public int DesignationId { get; set; }
    public int DepartmentId { get; set; }
    public string MgrCode { get; set; }
    public int LocationId { get; set; }
    public DateTime DOJ { get; set; }
    public bool IsActive { get; set; }
    public bool IsEligibleForCycle { get; set; }
    public bool IsNonEligibleApprover { get; set; }

    [ForeignKey("DepartmentId")]
    public Departments department { get; set; }
    [ForeignKey("DesignationId")]
    public Designations designation { get; set; }
    [ForeignKey("LocationId")]
    public Locations Loation { get; set; }
}