I’m working on a wiki project. MVC3 + EF4 Code First.
All classes from my model inherit from a main “EditBase” class. This assures that they all have ID, Username and CreatedDate. It also helps me create a generic Repository for basic CRUDs.
I wish to define a new entity called AbuseReport to handle flagging of incorrect/innacurate content:
public class AbuseReport : EditBase
{
public DateTime DateReported { get; set; }
public string EntityType { get; set; }
public int EntityId { get; set; }
public int ReportTypeId { get; set; }
public ReportType ReportType
{
get { return (ReportType) this.ReportTypeId; }
set { this.ReportTypeId = (int) value; }
}
public string Description { get; set; }
}
What would be the easiest way to retrieve an entity stored on the database starting from the information on a AbuseReport object? I can’t use foreign keys because the report can refer to any entity on the project.
I would need to call something like this:
Type modelType;
entityDictionary.TryGetValue(entityName, out modelType);
var rep = new Repository<modelType>();
I would store all the model types in the same repository. The repository key will have to contain the type of the model as well as its ID. I use the local class
RepositoryKeyfor this purpouse: