I am not sure if i am going about this in the right way....
I have two tables, Award and AwardVestingSettings and the relationship between these are 1 to 1.
I have a businessbase class
Public
Class Award......
AwardVestingSetting is also a businessbase class
.....
I am trying to make use of this through winforms databinding but cannnot set databinding through the designer for the properties of the AwardVestingSetting child object. I am not sure if I am implementing the one to one relationship as property correctly...?
Thanks
Thanks for the reply ajj3085. I agree with the approach of basing objects on the use case first.
I cannot seem to pickup the property VestingSetting as a Datamember for some reason? The property is Public so it should be visible as far as i can see..
As said, you probably need to think about the behaviour of your objects and not your database schema. Would you class Award and AwardVestingSettings as different objects, or one object that just happens to reside in more than one database table?
If they're two seperate objects then it could be worth using two datasources instead of one, with the second datasource calling AwardVestingSettings.GetAwardVestingSettings(award.VestingSettingsId);
If they do need to be a single object then it could be worth storing the AwardVestingSettings object internally to the Award class. You can then expose the AwardVestingSettings properties on the Award class.
Here's another example that may help:
A Customer may have a primary Address (mandatory) as well as a collection of other addresses (shipping, billing, alternate addresses etc). The primary address will be a 1-1 to the customer, and an application may treat the primary address as such. This will allow you to do the following:
Customer newCustomer = Customer.NewCustomer();
newCustomer.Name = "Bob Monkhouse";
newCustomer.StreetAddress = "41 Country Lane";
Internally the street address is being stored in an Address object, but the user of the object does not need to see that. It also makes databinding clearer.
The Customer class would contain the following:
public string StreetAddress
{
get
{
return this.primaryAddress.StreetAddress
}
}
I hope this helps.
Thanks for the reply and the insight to the use case/problem.
The Award and AwardVestingSetting should exist within in the same object in my use case and as far as I understand that is why the VestingSettings property is therefore allowing the usecase be exposed as single object and all the CRUD methods being handled by the parent object.
The AwardVestingSetting class was created from the point of view that it will be a child property so all the factory and data access methods were declared to identify it as being a child object and only exist within the parent context.
Factory Methods
-----
Public
Shared Function NewAwardVestingSetting(ByVal AwardId As Integer) As AwardVestingSetting If Not CanAddObject() Then----
Data Access Methods
Private Sub Child_Fetch(ByVal criteria As SingleCriteria(Of AwardVestingSetting, Integer))
...............
End Sub
OK, somethings fishy going on when using specifying a property of BusinessBase type and using Undo.
My Parent class has two properties of which both are BusinessListBase and undo works fine for these two.
If I attempt to load the of the BusinessBase type (AwardVestingSetting) property and then attempt undo I get the lovely Edit level mismatch in copystate error. :).
Private
Sub RebindUI(ByVal saveObject As Boolean, ByVal rebind As Boolean) ' disable events Me.AwardBindingSource.RaiseListChangedEvents = False Me.TransactionsBindingSource.RaiseListChangedEvents = False Me.VestingsBindingSource.RaiseListChangedEvents = False Me.VestingSettingsBindingSource.RaiseListChangedEvents = False Try ' unbind the UIUnbindBindingSource(
Me.VestingSettingsBindingSource, saveObject, False)UnbindBindingSource(
Me.VestingsBindingSource, saveObject, False)UnbindBindingSource(
Me.TransactionsBindingSource, saveObject, False)UnbindBindingSource(
Me.AwardBindingSource, saveObject, True) ' save or cancel changes If saveObject Then_award.ApplyEdit()
Try_award = _award.Save
Catch ex As Csla.DataPortalExceptionMessageBox.Show(ex.BusinessException.ToString(), _
"Error saving", MessageBoxButtons.OK, _MessageBoxIcon.Exclamation)
Catch ex As ExceptionMessageBox.Show(ex.ToString(), _
"Error Saving", MessageBoxButtons.OK, _MessageBoxIcon.Exclamation)
End Try Else_award.CancelEdit()
End If Finally ' rebind UI if requested If rebind ThenBindUI()
End If ' restore events Me.AwardBindingSource.RaiseListChangedEvents = True Me.TransactionsBindingSource.RaiseListChangedEvents = True Me.VestingsBindingSource.RaiseListChangedEvents = True Me.VestingSettingsBindingSource.RaiseListChangedEvents = True If rebind Then ' refresh the UI if rebinding Me.AwardBindingSource.ResetBindings(False) Me.TransactionsBindingSource.ResetBindings(False) Me.VestingsBindingSource.ResetBindings(False) Me.VestingSettingsBindingSource.ResetBindings(False) End If End Try End SubIn essence all three properties are the same except for the VestingSettings being of BusinessBase Type.
Copyright (c) Marimer LLC