开发者

What .Net Namespace contains Entity for use in a generic repository?

I have a question that I'm ashamed to ask, but I'm going to have a go at it anyway. I am creating a generic repository in asp.net mvc. I came across an example on this website which I find to be exactly what I was looking for, but there is one problem. It references an object - Entity - and I don't know what namespace it is in. I typically create my repositories and use Entity Framework but I decided to use a generic repository because I am using the same code in multiple projects over and over again.

Here is the code:

public interface IRepository { void Save(ENTITY entity) where ENTITY : Entity;

void Delete<ENTITY>(ENTITY entity)
    where ENTITY : Entity;

ENTITY Load<ENTITY>(int id)
    where ENTITY : Entity;

IQueryable<ENTITY> Query<ENTITY>()
    where EN开发者_运维问答TITY : Entity;

IList<ENTITY> GetAll<ENTITY>()
    where ENTITY : Entity;

IQueryable<ENTITY> Query<ENTITY>(IDomainQuery<ENTITY> whereQuery)
    where ENTITY : Entity;

ENTITY Get<ENTITY>(int id) where ENTITY : Entity;

IList<ENTITY> GetObjectsForIds<ENTITY>(string ids) where ENTITY : Entity;

void Flush();

}

Can someone please tell me what namespace Entity is in? As you can tell, a constraint is placed on the code so that it must be an Entity type. I know that there is an Entity in System.Data.Entity, but that isn't what I need. I have had instances before where I was looking for some namespace that took me forever to find, but I have searched and I'm unable to find the appropriate namespace to cast my generic items correctly. I could cast it as a class and be done with it, but it is bugging me that I can't find Entity anywhere.

Can someone help me....please..... :-)

Here is a link to the original post. ASP.NET MVC: How many repositories?


I think in the example you reference Entity is a base interface that all objects that can be fed from the repository need to implement.

I do NOT believe it is part of the framework but part of RichardOD's solution that he uses.

In this example, it could be as simple as just defining the type of Id used be all repository held items.

e.g

public interface Entity
{
  int Id {get; set;}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜