簡體   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