Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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/database/10.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# 继承遗留数据库实体框架中的一对多关系_C#_Database_Entity Framework_Ef Code First - Fatal编程技术网

C# 继承遗留数据库实体框架中的一对多关系

C# 继承遗留数据库实体框架中的一对多关系,c#,database,entity-framework,ef-code-first,C#,Database,Entity Framework,Ef Code First,我正在尝试将现有(遗留)数据库映射到实体框架,但遇到以下异常: 找不到类型“Product”。确保加载了所需的架构,并且正确导入了名称空间。靠近类型名称,第5行,第1列 public class BaseProduct { public int Id { get; set; } public virtual ICollection<Option> Options { get; set;} } public class Option { public int Pr

我正在尝试将现有(遗留)数据库映射到实体框架,但遇到以下异常:

找不到类型“Product”。确保加载了所需的架构,并且正确导入了名称空间。靠近类型名称,第5行,第1列

public class BaseProduct
{
   public int Id { get; set; }
   public virtual ICollection<Option> Options { get; set;}
}

public class Option
{

   public int ProductId{ get; set;}
   public int Time{ get; set;} 
   public int Value{ get; set;

   public virtual BaseProduct { get; set;}
}

public class Product : BaseProduct
{


}


我能做什么?

您是否尝试过:
HasRequired(x=>x.Product)。有许多(y=>y.Options)。HasForeignKey(x=>x.ProductId)?您还可以使用VS的EF6工具为您反向工程定义。嘿,它确实起作用了。但是,我将选项集合移动到基类,它不再工作了。
public ProductConfiguration() 
{
    HasKey(t => t.Id); 
}
public OptionConfiguration() 
{
    HasKey(x => new {x.ProductId, x.Time});
    HasRequired(x => x.Product); 
}