Is it possible to create a generic CRUD repository in VB.Net for MySQL connection without depending to any third party ORM?
I mean, MySQL CRUD depends on string to identify which table(s) and field(s) you want to access, meanwhile what we have is a .Net object.
Is the only way to achieve this is to use ORM and/or Reflection class? Can't we do something about the object or string to match each other?
Let's say I got this repository interface :
public interface IRepository<T> where T:class
{
void Insert(T entity);
void Delete(T entity);
IQueryable<T> GetAll();
T GetById(string id);
}
What comes in my mind after seeing this interface is to create a personal Repository for each of my object, even though the CRUD method is very similar.
For example I have to create a repository for Employee CRUD.
class EmployeeRepository : IRepository<Employee>
{
private string _query;
public IQueryable<Employee> GetAll(Employee entity)
{
_query = "SELECT * FROM tbl_msemployee";
//Do query here, which will eventually return a list of Employee object
}
}
I guess that is better to use an existing ORM to handle CRUD operations. You then build above this orm layer your repositories (t4 maybe or other code-generation) and your service layer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.