[英]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!
谢谢!
I think EF Complex Type mapping is what you need, see more here: 我认为您需要EF复杂类型映射,请在此处查看更多信息:
http://weblogs.asp.net/manavi/archive/2011/03/28/associations-in-ef-4-1-code-first-part-2-complex-types.aspx http://weblogs.asp.net/manavi/archive/2011/03/28/associations-in-ef-4-1-code-first-part-2-complex-types.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.