他のオブジェクトへの参照を持つ複雑なオブジェクトがあり、Webアプリケーションから保存しようとしています。
したがって、私のWebアプリケーションでは、ビジネスロジックを呼び出し、blから、DALファサードを呼び出し、次に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));
}
}
ダルファサードのコード:
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");