Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.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
Entity framework 实体框架:如何配置外键不在数据库中的关系?_Entity Framework_Entity Framework 6 - Fatal编程技术网

Entity framework 实体框架:如何配置外键不在数据库中的关系?

Entity framework 实体框架:如何配置外键不在数据库中的关系?,entity-framework,entity-framework-6,Entity Framework,Entity Framework 6,我有一些关系是基于不在数据库中的属性的,如下例,外键BrandID是从ProdID中提取的,是否可以用注释或fluent API配置这种关系 public partial class Prod { public string ProdID { get; set; } public string BrandID { get { return ProdID.Split('-')[0]; } } public virtual Brand Brand { get; se

我有一些关系是基于不在数据库中的属性的,如下例,外键
BrandID
是从
ProdID
中提取的,是否可以用注释或fluent API配置这种关系

public partial class Prod
{
    public string ProdID { get; set; }
    public string BrandID { get { return ProdID.Split('-')[0]; } }     
    public virtual Brand Brand { get; set; }
}

public class Brand
{
    public string BrandID { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Prod> Prods { get; set; }
}
公共部分类产品
{
公共字符串ProdID{get;set;}
公共字符串BrandID{get{return ProdID.Split('-')[0];}
公共虚拟品牌{get;set;}
}
大众品牌
{
公共字符串BrandID{get;set;}
公共字符串名称{get;set;}
公共虚拟ICollection产品{get;set;}
}

您需要了解EF如何管理关系。使用数据注释或FluentAPI可以创建实体之间的关系。你到底想实现什么?您想要一对多关系,而不是使用此属性。EF将无法使用
Prod.BrandID
,因为它不能是映射属性。@M.Wiśnicki,是的,我想配置
Prod
Brand
之间的一对多关系。您需要知道EF如何管理关系。使用数据注释或FluentAPI可以创建实体之间的关系。你到底想实现什么?您想要一对多关系,而不是使用此属性。EF将无法使用
Prod.BrandID
,因为它不能是映射属性。@M.Wiśnicki,是的,我想配置
Prod
Brand
之间的一对多关系。