我有两种方法具有相同的包含部分(这些方法仅用于描述问题)
public Car GetCarByChildEntityId(long id)
{
var query = DataContext.AsQueryableFor<RTraining>()
.Where(rb => rb.Id == id)
.Include(rb => rb.Car.CarStatus)
.Include(rb => rb.Car.item.Customer)
.Include(rb => rb.Car.item.MyItem.Wheel.Customer);
return executeQuery(query).SingleOrDefault().Car;
}
public IEnumerable<IEntity> GetEntities()
{
var query = DataContext.AsQueryableFor<RTraining>()
.Include(rb => rb.Car.CarStatus)
.Include(rb => rb.Car.Item.Customer)
.Include(rb => rb.Car.Item.MyItem.Wheel.Customer);
return executeQuery(query);
}
这三个包括如何使通用以避免代码重复。