I have a couple questions on how to create my repository classes. I will give an example of the type of data that I am working with. I am considering using Dapper or PetaPoco, but that shouldn't really matter. The classes are related, but they are not dependent on each other. I have 3 POCO classes (Carrier, Driver, Vehicle) defined below:
public class Carrier
{
}
public class Driver
{
}
public class Vehicle
{
}
Currently, I have a repository for each, but I did consider having one repository for all. I considered making a generic repository, but for some reason I felt it was unnecessary. One big question I have is should the sql to be executed by the queries be done inside the repository methods or should it be passed into the repository methods, for example (Insert(string sql, Carrier carrier) or Insert(carrier))?
Here are my empty repositories:
public class CarrierRepository
{
//Get connection string information
public Carrier GetAll()
{
throw new NotImplementedException();
}
public Carrier Find(int id)
{
throw new NotImplementedException();
}
public void Delete(Carrier carrier)
{
throw new NotImplementedException();
}
public Carrier Insert(Carrier carrier)
{
throw new NotImplementedException();
}
public Carrier Update(Carrier carrier)
{
throw new NotImplementedException();
}
}
public class DriverRepository
{
public Driver GetAll()
{
throw new NotImplementedException();
}
public Driver Find(int id)
{
throw new NotImplementedException();
}
public void Delete(Driver driver)
{
throw new NotImplementedException();
}
public Driver Insert(Driver driver)
{
throw new NotImplementedException();
}
public Driver Update(Driver driver)
{
throw new NotImplementedException();
}
}
public class VehicleRepository
{
public Vehicle GetAll()
{
throw new NotImplementedException();
}
public Vehicle Find(int id)
{
throw new NotImplementedException();
}
public void Delete(Vehicle vehicle)
{
throw new NotImplementedException();
}
public Vehicle Insert(Vehicle vehicle)
{
throw new NotImplementedException();
}
public Vehicle Update(Vehicle vehicle)
{
throw new NotImplementedException();
}
}
Is it also possible to use some base class so I don't have to call a method to get the connection string in each respository? What are some improvements I can do to make this shorter and are generics a better way to go?
Aucun commentaire:
Enregistrer un commentaire