I have a WPF application using the MVVM pattern and MVVM Light Tookkit that is accesing a MSSQL server. Below would be a sample database (the database I have is more complex):
Employee Table:
|Name | ShipToLocation
---------------|--------------------
|John | 1
ShipToLocation Table:
|Code | CityName
------|------------------
| 1 | New York
I have used EntityFramwork to Create Objects out of my database tables. The problem I am having is in my program now, I am having to use a lot of IValueConverters like such:
<ListBox Grid.Row="1" Grid.ColumnSpan="3" ItemsSource="{Binding Employees}" HorizontalContentAlignment="Stretch" SelectedItem="{Binding ThisEmployee}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource IntToShipTo}">
<Binding Path="VendorCode" Mode="OneWay"/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}" Path="DataContext.ShipToLocations"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
In my ViewModel there is a property called Employees that holds a list of Emplyoyee, and a property called ShipToLocations that has a list of all Ship To Locations. I have to use the RelativeSource in order to access the ShipToLocations Property since the ItemSource of the ListBox is set to "Employees", which is causing design time view problems
I have this kind of linking going on in alot of places, and I will need to make a converter for each one. This seems like alot of overhead, and a Unit Testing nightmare.
What I was wondering was, would it be bad practice to, in my Employee Table, add a column called ShipToFriendlyName, and then attach a trigger on the ShipToLocation field that will update the frienldy name when the int is changed. This would avoid the need to be doing database calls every time I need to find out what the friendly name of the Integer is. Thank you