'Is it right to use same method with parameters to get object or object and related objects with include?
I have the following method.
public Car GetCar(int carId)
{
using (var context = new Context())
return context.Cars.SingleOrDefault(x => x.Id == carId);
}
However, I would like to use it in situations that it gives me just this item or this item with some objects related. Is it right to use parameter for distinction or should I use different methods? What is better? I don't want all objects always for performance reasons.
This is a simple example:
public Car GetCar(int carId, bool isRepairing)
{
using (var context = new Context())
{
if(isRepairing){
return context.Cars.Include(x => x.Mechanics).SingleOrDefault(x => x.Id == carId);
}
else
{
return context.Cars.SingleOrDefault(x => x.Id == carId);
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
