【问题标题】:Entities inheriting from generic interfaces in Entity Framework从实体框架中的通用接口继承的实体
【发布时间】:2016-07-10 22:36:41
【问题描述】:

我有以下接口:

public interface IInitializable
{
    void Initialize ();
}

public interface IPersistXmlElementTo
{
    XmlElement ToXmlElement (XmlDocument document);
}

public interface IPersistXmlElement<T>:
    IPersistXmlElementTo,
    IInitializable
{
    T FromXmlElement (XmlElement element);
}

public interface IPersistXmlDocumentTo:
    IPersistXmlElementTo
{
    XmlDocument ToXmlDocument ();
}

public interface IPersistXmlDocument<T>:
    IPersistXmlDocumentTo,
    IPersistXmlElement<T>,
    IInitializable
{
    T FromXmlDocument (XmlDocument document);
}

public interface ICloneable<T>
    where T: ICloneable<T>
{
    T Clone ();
}

public interface ICopyable<T>:
    IInitializable,
    ICloneable<T>
    where T: ICopyable<T>
{
    T CopyFrom (T source);
    T CopyTo (T destination);
}

public interface IEntity
{
    long Id { get; set; }
    byte [] TimeStamp { get; set; }
    DateTime DateTimeCreated { get; set; }
    DateTime DateTimeModified { get; set; }
}

目前所有实体类都继承自IEntity。我现在希望 IEntity 从上面的接口继承。这意味着将 IEntity 转换为通用接口。比如:

public interface IEntity<T>:
    IPersistXmlDocument<T>,
    IPersistXmlElement<T>,
    ICloneable<T>,
    ICopyable<T>,
    IInitializable
    where T: IEntity<T>

我在从类继承时遇到了 EF 问题,但到目前为止接口似乎工作正常。有什么需要注意的问题吗?从Entity: IEntity 切换到Entity: IEntity&lt;Entity&gt; 需要EF 中的任何特殊配置吗?

【问题讨论】:

    标签: c# .net entity-framework generics interface


    【解决方案1】:

    事实证明,通用接口对 EF 没有任何影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-19
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多