Workaround a la navegación entre relaciones en Dynamic Data

Si se te presenta el error A property with name ‘Entidad.Campo’ does not exist in metadata for entity type ‘WebAppDataEntitiesA.EntidadDestino’.

Es muy probable que lo puedas resolver con este workaround disponible en Codeplex.

http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16367

Para mis lectores que desean saber la implementación en español aquí les va.

Dynamic Data Entity Web Application

1. Botón derecho sobre la aplicación web y seleccionen “Agregar Referencia”, Seleccionan Browse y seleccionan Microsoft.Web.DynamicData.dll del archivo zip que descargaron de CodePlex.
2. Cuando registran su Entity Framework Model en el Global.asax realicen el siguiente cambio:

En lugar de esto:

model.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false });

Usen esto:

C#
model.RegisterContext(new Microsoft.Web.DynamicData.EFDataModelProvider(typeof(YourDataContext)), new ContextConfiguration() { ScaffoldAllTables = false });

VB
model.RegisterContext(New Microsoft.Web.DynamicData.EFDataModelProvider(GetType(YourDataContext)), New ContextConfiguration() With { .ScaffoldAllTables = False })

Noten que la diferencia es reemplazar typeof(YourDataContextType) con new Microsoft.Web.DynamicData.EFDataModelProvider(typeof(YourDataContext)).

3. Abran el DynamicData\FieldTemplates\ForeignKey.ascx. Y remplacen el método GetDisplayString con este método:

C#
protected string GetDisplayString() {
try {
return FormatFieldValue(ForeignKeyColumn.ParentTable.GetDisplayString(FieldValue));
} catch (Exception) {
return ForeignKeyColumn.ParentTable.DisplayName;
}
}

VB
Protected Function GetDisplayString() As String
Try
Return FormatFieldValue(ForeignKeyColumn.ParentTable.GetDisplayString(FieldValue))
Catch ex As Exception
Return ForeignKeyColumn.ParentTable.DisplayName
End Try
End Function

Saludos y espero les sirva.