paulthepaddy
Well-known member
Hi guys,
As title says im using EF5 legacy
Im just wondering if it is possable and not overly complicated to 'catch' when an object is being added to another object.
So i have a Car table/object and an Order table/object, im looking for something like the onpropertychanged when i add an order to the car is it possable to catch this event, im looking to perform some business logic i think it would be called.
Currently I am using my orderstatus property and carstatus property changing to manage these but i think there is a better way of doing it, im worried that for some reason the order wasn't saved correctly to the car that it would start to give me wrong totals and wrong status and i feel the best time to change the status and change the money side of things are when the order is actually added to the car. If this is something rather complicated then i might just leave it as my programming skills/knowledge i would consider are rather limited.
This is an example of how I am doing this, slightly off topic but when im chekcing my cars for its orders because most cars will have 1 order and a few will have more than one.
Is it more efficient to check the Orders.Count and execute the code in blue or just execute the code in red regardless of only 1 order.
As title says im using EF5 legacy
Im just wondering if it is possable and not overly complicated to 'catch' when an object is being added to another object.
So i have a Car table/object and an Order table/object, im looking for something like the onpropertychanged when i add an order to the car is it possable to catch this event, im looking to perform some business logic i think it would be called.
Currently I am using my orderstatus property and carstatus property changing to manage these but i think there is a better way of doing it, im worried that for some reason the order wasn't saved correctly to the car that it would start to give me wrong totals and wrong status and i feel the best time to change the status and change the money side of things are when the order is actually added to the car. If this is something rather complicated then i might just leave it as my programming skills/knowledge i would consider are rather limited.
VB.NET:
[COLOR=#0000ff]If Me.Car.Orders.Count = 1 Then[/COLOR]
[COLOR=#0000ff] Select Case Me._Order_Status[/COLOR]
[COLOR=#0000ff] Case OrderStatus.ToBeInvoiced[/COLOR]
[COLOR=#0000ff] Me.Car.Car_Status = Car_Status.ToBeInvoiced[/COLOR]
[COLOR=#0000ff] Case OrderStatus.Invoiced[/COLOR]
[COLOR=#0000ff] Me.Car.Car_Status = Car_Status.Invoiced_AwaitingPayment[/COLOR]
[COLOR=#0000ff] Case OrderStatus.Paid[/COLOR]
[COLOR=#0000ff] Me.Car.Car_Status = Car_Status.FullyPaid[/COLOR]
[COLOR=#0000ff] End Select[/COLOR]
ElseIf Me.car.Orders.Count > 1 Then
[COLOR=#ff0000] Dim Status As New List(Of Int16)[/COLOR]
[COLOR=#ff0000]
[/COLOR]
[COLOR=#ff0000] For Each Order In Me.Car.Orders[/COLOR]
[COLOR=#ff0000] Status.Add(Order.Order_Status)[/COLOR]
[COLOR=#ff0000] Next[/COLOR]
[COLOR=#ff0000]
[/COLOR]
[COLOR=#ff0000] Status.Reverse()[/COLOR]
[COLOR=#ff0000]
[/COLOR]
[COLOR=#ff0000] Select Case CType(Status.First, OrderStatus)[/COLOR]
[COLOR=#ff0000] Case OrderStatus.ToBeInvoiced[/COLOR]
[COLOR=#ff0000] Me.Car.Car_Status = Car_Status.ToBeInvoiced[/COLOR]
[COLOR=#ff0000] Case OrderStatus.Invoiced[/COLOR]
[COLOR=#ff0000] Me.Car.Car_Status = Car_Status.Invoiced_AwaitingPayment[/COLOR]
[COLOR=#ff0000] Case OrderStatus.Paid[/COLOR]
[COLOR=#ff0000] Me.Car.Car_Status = Car_Status.FullyPaid[/COLOR]
[COLOR=#ff0000] End Select[/COLOR]
End If
Public Sub ForceTotals()
Dim _Due As New Integer
Dim _Paid As New Integer
Dim _Total As New Integer
For Each order As Order In Me.Orders
If order.Order_Status = OrderStatus.Paid Then
_Paid += order.Order_Amount
Else
_Due += order.Order_Amount
End If
_Total += order.Order_Amount
Next
Me.Car_AmountDue = _Due
Me.Car_AmountPaid = _Paid
Me.Car_AmountTotal = _Total
End Sub
This is an example of how I am doing this, slightly off topic but when im chekcing my cars for its orders because most cars will have 1 order and a few will have more than one.
Is it more efficient to check the Orders.Count and execute the code in blue or just execute the code in red regardless of only 1 order.