I have an N-Layer solution in .Net with PetaPoco as microORM. I get the entities generated from the template generator of PetaPoco. This entities T derive from the base class Record and then I extend them adding more data access facilities and customs Save() and Delete() methods that overrides the Record defaults methods.
Then when I create the generic repository the methods that get called are from the base class Record and not my custom ones from the entities. I need help designing my generic repository class so when I call an entityRepository.Delete() method the Delete() method that gets called is the one from the entity and not the one from the default one from the Record class.
Here is my code. Any suggestion is well received.
The generic repository class
public abstract class GenericRepository<T> : IGenericRepository<T> where T : Record<T>, new()
{
public void Delete(T entity)
{
entity.Delete();
}
}
The overrided Delete method from the entity (the method I want to get call)
public partial class Document : Record<Document>
{
public new int Delete()
{
int rowsAffected;
using (var uow = RealityDB.GetInstance().GetTransaction())
{
rowsAffected = base.Delete();
LogSystem("Deleting", "Deleting a document", 0, 0, GUID);
uow.Complete();
}
return rowsAffected;
}
}
I log in the entity class and think is bad designed, but I don't now if this logic should be in the entities repository or in an unit of work implementation, which I don't know how to do well. Again any help would be appreciated, thanks in advance.
Aucun commentaire:
Enregistrer un commentaire