开发者

Using generic-based role pattern with EntityFramework 4

Maybe I haven't quite get the whole thing about models. I tought that, it was probably wrong, EF framework could map any kind of class. So I did provide classes with different interfaces, with ToString() methods and so on.

I was thinking of reusable/flexible structure of classes for some kind of public organization.

For example, there are next classes

[Serializable]
public abstract class AbstractRole
{
    public String Title { get; set; }

    public abstract void ExecuteRole();
 开发者_JAVA技巧   public abstract Decimal GetSalary();

    // ToString(...) implementations and so on
}

[Serializable]
public class Employee<T> : IComparable<Employee<T>>, IFormattable where T : AbstractRole
{
    private Person person;        
    public T Role { get; set; }

    // interfaces implementations...       
}

So all I wanted is to get flexibility to change employee's role in time and not to bind to its instance (avoid inheritance).

But later I read that generics are not supported by EF.

What should I do?


In case of entity framework you must provide exact type. Base classes are supported only if whole inheritance tree is mapped as well. Interfaces and generic types are not supported at all.

That means that reusable and flexible architecture is not something which can use EF.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜