mercredi 13 janvier 2016

What is IEntity in this code for a generic repository pattern?

I have seen this code in a few places. What is IEntity doing in the code below? I know that IEntity is not an interface, even though it's prefixed with "I". Additionally, I understand it may be acting as an ID for the entities returned from the repository. When would this ID be set? I'm looking for a good explination of the interface use of IEntity and how it relates to "T".

Code from: http://ift.tt/1rv1a6H

public class IEntity
{
    public string Id; 
}

public interface IRepository<T> where T: IEntity
{

    IEnumerable<T> List { get; }
    void Add(T entity);
    void Delete(T entity);
    void Update(T entity);
    T FindById(int Id);

}

Aucun commentaire:

Enregistrer un commentaire