EF 4.0 Generator Inheritance

I have a class like this

public abstract class BaseType<T>
{
  public string Name {};
  public T TypedValue { 
    get {
       return GetTypedValue(PersistedValue);
        }  
  };
  public string PersistedValue {} 
  public abstract T GetTypedValue(PersistedValue);
}

then many derived classes such as

public class IntegerType:BaseType<int>
{
 ...
}

Is it possible to map this hierarchy using EF 4.0 using a table on the inheritance scheme? Currently generated code generates an error because it generates a property of type

public <T> ObjectSet<TypedAttribute<T>> TypedAttributes
{
     get 
     { 
        return _typedAttributes  ?? (_typedAttributes = CreateObjectSet<TypedAttribute<T>>("TypedAttributes")); }
     }
private ObjectSet<TypedAttribute> _typedAttributes;
+3
source share
1 answer

I don’t think so because:

  • Inheritance inheritance requires the base class to be an entity in EDMX.
  • When inheriting, it is used ObjectSetfor the base type. What common argument would you use to instantiate ObjectSetwhen it should be used to extract any subtype?

( POCOs). EDMX . POCO . , , , POCO , EDMX, , EDMX. , . , .

:

, EDMX: IntegerValue DoubleValue. POCO :

public abstract class BaseType<T>
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual T Value { get; set; }
}

public class IntegerValue : BaseType<int>
{ }

public class DoubleValue : BaseType<double>
{ }

.

+2

All Articles