1
I’m trying to make a generic CRUD for my project. However as I used Databasefirst I do not see how to have a generic class of Entity that can be inherited. Because it doesn’t make any sense, eventually when I upgrade the bank, I would have to go into all over 60 classes of the tables and add the inheritance again. I want the entity classes that Entity Framawork generated pure, such as were generated.
But as you can see I have this property problem not defined, since as I said I don’t want to have anything like a "Entidadegeral".
Does anyone know of any way to achieve this? Like has some class that the Entity uses behind the scenes that can be used in the constraint Where. Or maybe if instead of Generics I used Reflection? Any ideas?
Edited: Code Added.
public class DaoEF<TEntity> : IDaoEF<TEntity>
where TEntity : class
{
public GPSdEntities _dbContext { get; set; } = new GPSdEntities();
public async Task<TEntity> GetById(int id)
{
return await _dbContext.Set<TEntity>()
.AsNoTracking()
.FirstOrDefaultAsync(e => e.Id == id);
}
publish the code and not an image of it, get more dynamic help.
– Igor Carreiro
Code added... Wanted to show error, so image.
– AlamBique