简体   繁体   English

EF代码优先:尝试获取子属性的参数以显示在父类的表中

[英]EF Code First: Trying to get a child property's parameters to appear in the parent class' table

I have a class, "Search". 我有一堂课,“搜索”。 See definition below: 请参阅下面的定义:

public class Search
{
    [Key]
    public int SearchID { get; set; }
    public int UserID { get; set; }

    public SearchParameters SearchParameters { get; set; }

    public ICollection<SearchProvider> SearchProviders { get; set; }
    public User User;
}

SearchParameters is a class with value types, and a few sub-classes; SearchParameters是一个具有值类型和一些子类的类。 as defined below: 定义如下:

public class SearchParameters
{
    public List<string> SearchTerms { get; set; }
    public int MaxRecords { get; set; }
    public DistanceParameter Distance { get; set; }
    public PriceRangeParameter PriceRange { get; set; }
}

The idea is that I do not want a separate SearchParameters table that has to link to the Search table because every property of the search is always one to one (Except for SearchTerms). 我的想法是,我不希望有单独的SearchParameters表必须链接到Search表,因为搜索的每个属性始终都是一对一的(SearchTerms除外)。 Really, what I want EF to do is 'bring up' the child classes' properties so we end up with All the properties of SearchParameter in the SearchTable (and all the parameters of the DistanceParameter and PriceRangeParameter objects themselves). 确实,我希望EF要做的是“调出”子类的属性,因此我们最终获得了SearchTable中SearchParameter的所有属性(以及DistanceParameter和PriceRangeParameter对象本身的所有参数)。 What annotations or other logic would I need for this to work? 我需要什么注释或其他逻辑才能起作用? Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EF4 Code First:同一张表中的父/子关系,如何获得逆属性? - EF4 Code First: Parent/Child relationship in same table, how to get inverse property? 具有相同类别的2个FK的EF代码第一个映射表 - EF code first mapping table with 2 FK's from same class 我如何首先使用可重用的查询/表达式和EF代码在父级中获取子实体作为DTO? - How can I fetch child entities as DTO in parent using reusable queries/Expression's with EF code first? EF Code First属性到同一个表 - EF Code First Navigation Property to same table 多个父实体首先在EF代码中包含一个子实体 - multiple parent Entities with one child entity in EF code first EF 5代码首先,具有级联删除功能的多个父级子级? - EF 5 Code First, multiple parent child with cascade delete? EF代码优先+从父级删除子级对象? - EF Code first + Delete Child Object from Parent? EF 4.1父级子代和继承映射的代码优先问题 - EF 4.1 Code First problem with parent child and Inheritance Mapping 首先使用EF代码,子级包含父级对象列表 - EF code first, child holds a list of parent objects 如何在父实体中拥有一个属性,该父实体的值属于子实体,而EF6和Code-First则将其下两层 - How to have a property in a parent entity whose value belongs to a child entity two levels down with EF6 and Code-First
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM