Tuesday, 20 November 2012

Using Reflection to retrieve Entity Framework Data using a Column Name String

If you ever need to retrieve data from EF using the name of a column, rather than the built in Intellisense, then the following vb.net code snippet may help.

GetType(TypeOfEntity).GetProperty(NameOfColumn).GetValue(ActualEntity, Nothing)


  • TypeOfEntity is the name of the Entity from which you wish to retrieve data.
  • NameOfColumn is obviously the Name of the Column from which you wish to retrieve data.
  • ActualEntity is a reference to the Entity itself, from which the data is to be retrieved.

The above can help if you need to retrieve data based on a column name which is defined by another function. Such as in the following example;

You have a table called Users with columns called Screen1Edit and Screen2Edit.

You can then retrieve the values in Screen1Edit or Screen2Edit depending upon which you require, supplied in a variable called strScreenName;


GetType(Users).GetProperty(strScreenName).GetValue(Users, Nothing)

Obviously you must be careful to supply the exact name of the column into the Column Name!

Note: For c# replace GetType with TypeOf.

SQL Server 2008 R2 Management Studio (SSMS) Open File Dialog slow

A quick tip if your SSMS is slow when using the Open File or Save File Dialog Boxes…. Disconnect any Network Shares which are unreachable.

Wednesday, 7 November 2012

Enabling Word Wrap in the WPF DataGrid Column Headers

To enable Word Wrapping in the WPF Data Grid Column Header, simply add the following code snippet to your Application.xaml file;

<Style TargetType="{x:Type primitives:DataGridColumnHeader}">
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <TextBlock TextWrapping="Wrap" Text="{Binding}"></TextBlock>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>