如何为继承的泛型类型创建实体数据模型? [英] How to create an Entity Data Model for inherited generic types?
本文介绍了如何为继承的泛型类型创建实体数据模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public abstract class WahWahProperty
{
public string Name {get;组; }
public abstract Type PropertyType {get; }
}
// ----------------
public class WahWahProperty< T> :WahWahProperty
{
public T Value {get;组;
public override类型PropertyType
{
get {return typeof(T); }
}
}
// ----------------
public class WahWahContainer
{
public List< WahWahContainer>孩子{get {...}; }
public List< WahWahContainer>父母{get {...}; } // multipleParentsallowed
public List< WahWahProperty>属性{get {...}; }
// ...这里有更多的道具...
}
任何想法?
解决方案
EF不支持通用实体类型(这似乎是您正在做的) / p>
尽管我们在EF 4.0中进行了更改(不是在Beta1中),因此您将能够使用从泛型类派生的非泛型类作为实体。 / p>
无论如何希望这有助于
Alex
程序实体框架团队
I have no clue how i can get an existing object structure based on the following classes (simplified) into a database using Entity Framework (EF is a constraint, i have to use it).
public abstract class WahWahProperty
{
public string Name { get; set; }
public abstract Type PropertyType { get; }
}
// ----------------
public class WahWahProperty<T> : WahWahProperty
{
public T Value { get; set; }
public override Type PropertyType
{
get { return typeof(T); }
}
}
// ----------------
public class WahWahContainer
{
public List<WahWahContainer> Children { get {...}; }
public List<WahWahContainer> Parents { get {...}; } // multiple "Parents" allowed
public List<WahWahProperty> Properties { get {...}; }
//... some more props here ...
}
Any ideas?
解决方案
The EF doesn't support generic Entity types (which seems to be what you are doing).
Although we have made a change in EF 4.0 (not in Beta1) so you will be able to use a non-generic class derived from a generic class as an Entity.
Anyway hope this helps
Alex
Program Manager Entity Framework Team
这篇关于如何为继承的泛型类型创建实体数据模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文