简体   繁体   中英

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; 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). 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). What annotations or other logic would I need for this to work? Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM