我有一个复杂的对象,它引用了其他对象,我试图从我的 Web 应用程序中保存它。
因此,在我的 web 应用程序中,我调用了业务逻辑,从 bl 中,我调用了 DAL Facade,然后是 DAL。
当我执行 Insert 方法时,我遇到了异常。
DAL 层中的代码,这是引发异常的地方。
public void InsertEcoBonusRequest(EcoBonusRequest ecoBonusRequest)
{
_context.EcoBonusRequests.Add(ecoBonusRequest);
}
Unitofwork.cs 中的代码
public void Save()
{
_context.SaveChanges();
}
private RequestBaseRepository _requestBaseRepository;
public EcoBonusRequestRepository EcoBonusRequestRepository
{
get
{
return _ecobonusworkflowRepository ??
(_ecobonusworkflowRepository = new EcoBonusRequestRepository(_context));
}
}
dal门面中的代码:
private static readonly UnitOfWork UnitOfWork = new UnitOfWork();
public void Save(EcoBonusRequest ecoBonusRequest)
{
UnitOfWork.EcoBonusRequestRepository.InsertEcoBonusRequest(ecoBonusRequest);
}
BL中的代码
public void Save(EcoBonusRequest ecoBonusRequest)
{
EcoBonusRequestFacade.Save(ecoBonusRequest);
}
**Code in the page.aspx.cs, as you can see the element ecobonusworkflow is neverstored in the database, but the navigation entities are stored already.**
var dealer = DealerBL.GetDealer(Nuteres);
var requester = RequesterBL.GetRequester(int.Parse(DdlRequester.SelectedItem.Value));
var selectedVehicle = VehicleBL.GetVehicle(VehicleInformationControl.Chassis);
var ecoBonusWorkflow = new EcoBonusRequest
{
IsOnHold = true,
AmmountWithoutVAT = decimal.Parse(TxtVatExcluded.Text),
AmmountWithVAT = decimal.Parse(TxtVatIncluded.Text),
BrandReturnedVehicle = TxtBrandReturnedVehicle.Text,
ChassisReturnedVehicle = TxtChasisReturnedVehicle.Text,
Percentage = (decimal.Parse(TxtVatExcluded.Text)/VehicleInformationControl.InvoicedAmmount)*100,
Comments = TxtComments.Text,
Customer = new Customer
{
FirstName = TxtFirstName.Text,
LastName = TxtLastName.Text,
Address = new Address
{
Street = TxtStreet.Text,
Number = TxtNumber.Text,
Box = TxtBox.Text,
City = TxtCity.Text,
Zip = TxtZip.Text
}
},
CurrentStatus = "Approval1",
Dealer = dealer,
Requester = requester,
VehicleDesctructionDate = DateTime.Parse(TxtVehicleDestructionDateReturnedVehicle.Text, userCulture),
DestructionCertificateNumberReturnedVehicle = TxtDestructionCertificateNumberReturnedVehicle.Text,
TypeReturnedVehicle = TxtTypeReturnedVehicle.Text,
Vehicle = selectedVehicle
};
EcoBonusRequest = ecoBonusWorkflow;
UploadFiles();
RedirectToPage("~/Requests/confirmation.aspx");