我一直收到此错误消息,即使我尝试
GetById()
(我的通用存储库中的一种方法)的表中没有 WarehouseBatchContentId
。我正在尝试获取 WarehouseBatchId
表中的 WarehouseBatch
而不是 WarehouseBatchContent
表中确实有一个 WarehouseBatchContentId
。
我看不出这种混淆发生在哪里!
产品配料器应用:
public class ProductBatcher : IBatchProducts
{
private readonly IUnitOfWork _uow;
private readonly IGenericRepository<WarehouseBatchContent> _warehouseBatchContentRepo;
private readonly IGenericRepository<WarehouseBatch> _warehouseBatchRepo;
public ProductBatcher(IGenericRepository<WarehouseBatchContent> warehouseBatchContentRepo, IUnitOfWork uow, IGenericRepository<WarehouseBatch> warehouseBatch)
{
_warehouseBatchContentRepo = warehouseBatchContentRepo;
_uow = uow;
_warehouseBatchRepo = warehouseBatch;
}
/*creating a method which takes all the parameters and is called in the program.cs file*/
public void BatchMover(int Id)
{
Console.WriteLine(dto);
var oldBatch = _warehouseBatchRepo.GetById(Id);
if (oldBatch == null)
{
throw new Exception("No batch matching the input");
}
}
}
WarehouseBatchContent
域:
namespace Domain;
public class WarehouseBatchContent
{
protected WarehouseBatchContent()
{
WarehouseBatches = new List<WarehouseBatch>();
}
public WarehouseBatchContent(int warehouseBatchId, int manufactoringLotId, int quantity)
{
WarehouseBatchId = warehouseBatchId;
ManufactoringLotId= manufactoringLotId;
Quantity= quantity;
}
public int WarehouseBatchContentId { get; private set; }
public int WarehouseBatchId { get; private set; }
public int ManufactoringLotId { get; private set; }
public int Quantity { get; private set; }
public virtual ManufactoringLot? ManufactoringLotNavigation { get; set; }
public virtual WarehouseBatch? WarehouseBatchNavigation { get; set; }
public virtual ICollection<WarehouseBatch> WarehouseBatches { get; protected set; }
}
WarehouseBatch
域:
namespace Domain;
public class WarehouseBatch
{
public WarehouseBatch(int locationId)
{
LocationId = locationId;
}
public int WarehouseBatchId { get; private set; }
public int LocationId { get; private set; }
public virtual Location? LocationNavigation { get; set; }
public virtual ICollection<WarehouseBatchContent> WarehouseBatchContents { get; set; } = new List<WarehouseBatchContent>();
}
}
有什么建议吗?
我期待
GetById()
使用WarehouseBatchId
作为ID参数,而不是WarehouseBatchContentId
。
[Key]
public int WarehouseBatchId { get; private set; }
尝试像这样从 dataAnnotations 库中设置键 使用 System.ComponentModel.DataAnnotations