繁体   English   中英

从实体框架的通用接口继承的实体

[英]Entities inheriting from generic interfaces in Entity Framework

我有以下界面:

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<Entity>所需的EF中的任何特殊配置?

事实证明,通用接口对EF毫无影响。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM