views:

34

answers:

1

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 ENTITY : 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. http://stackoverflow.com/questions/1472719/asp-net-mvc-how-many-repositories

A: 

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

Kindness,

Dan

Daniel Elliott
Dan you are sooooo right! I just started reading .Net Domain Driven Design in C# and the answer immediately became clear. It was just as you said. Now I feel a little silly for not thinking of this earlier. I feel like a newbie all over again as I move from asp.net to asp.net mvc. I wasn't thinking. Thanks again.
Sara