Instead of the adding search method to every class like this;
public List<InvoiceDetail> SearchById(int Id)
{
return db.Query<InvoiceDetail>()
.Where(x => x.Id == Id)
.ToList();
}
How to add a method to base class like this;
public virtual List<T> SearchById(int Id)
{
return db.Query<T>()
.Where(x => x.Id == Id)
.ToList();
}
"T does not contain a definition for Id"
Because Id is the definition of Detail entities.
You can achieve this by creating a base class as:
Then make the appropriate entity classes inherit from
BaseEntityas:Now for your search method you can use the
where T : classconstrain as: