简体   繁体   中英

Entities inheriting from generic interfaces in Entity Framework

I have the following interfaces:

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; }
}

All entity classes inherit from IEntity at the moment. I'd now like IEntity to inherit from the interfaces above. That means converting IEntity to a generic interface. Something like:

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

I've had trouble with EF while inheriting from classes but interfaces seem to work ok so far. Are there any gotchas to look out for? Any special configurations in EF required to switch from Entity: IEntity to Entity: IEntity<Entity> ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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