您好,当我在一个方法中两次访问通用存储库的相同方法时,出现此错误。
var polyTables = _vehicleService.GetAll().ToList()
.Select(p => new PolyTable
{
VinNumber = p.ChassisNumber ?? "-",
BrandName = p.BrandName,
FirstRegisterDate = p.FirstRegistrationDate,
ModelCode = p.ModelCode,
Plate = p.Plate ?? "-",
CreatedBy = 1,
IsActive = true,
AuthorizedServiceId = p.AuthorizedServiceId,
Customer = GetLastCustomerName(p.Id, periodicCodes)
}).ToList();
private string GetLastCustomerName(string vehicleId,IEnumerable<PeriodicCode> periodicCodes)
{
var invoices = _invoiceService.GetByVehicle(vehicleId);
var lastInvoiceLine = _invoiceLineService.GetLastInvoiceLineByInvoices(invoices, periodicCodes);
var customer =new Customer();
if (lastInvoiceLine != null )
customer = _customerService.GetById(lastInvoiceLine.CustomerNumber);
return customer.Name + " " + customer.SurName;
}
在这里给我通用存储库方法
public IEnumerable<T> Find(Expression<Func<T, bool>> predicate, params Expression<Func<T, object>>[] includes)
{
if (includes == null)
return Context.Set<T>().Where(predicate);
else
return includes.Aggregate(Context.Set<T>().Where(predicate).AsQueryable(), (current, includeProperty) => current.Include(includeProperty));
}
此处的GetByVehicle方法
public IEnumerable<Invoice> GetByVehicle(string vehicleId) =>
_genericRepository.Find(s => s.VehicleId == vehicleId);
答案 0 :(得分:0)
我通过更改此处的IEnumerable To来解决此问题
public InvoiceLine GetLastInvoiceLineByInvoices(List<Invoice> invoices, List<InvoiceLine> invoiceLine)
{
if (invoices != null)
{
return invoiceLine.Where(s => s.WorkmanshipId != null && invoices.Select(p=> p.Id).Contains(s.InvoiceId) ).OrderByDescending(s=> s.InvoiceDate).FirstOrDefault();
}
return null;
}
Maartens的评论很有帮助。