Используйте проекцию LINQ для выравнивания (денормализации) графа сущностей. Вы можете либо создать новый класс ViewModel
, либо связать его с анонимным классом, например:
var viewList = (
from entity in entityList
select new
{
Field1 = entity.Field1,
Field2 = entity.Relation.AnotherField,
Field3 = entity.Field3 + entity.Relation.YetAnotherField
}).ToList();
myGridView.DataSource = viewList;
myGridView.DataBind();
Используйте Field1
, Field2
в свойствах GridView
для привязок данных.
Редактировать
Вышеуказанная проекция в лямбда-синтаксисе:
var viewList = entityList
.Select(entity => new
{
Field1 = entity.Field1,
Field2 = entity.Relation.AnotherField,
Field3 = entity.Field3 + entity.Relation.YetAnotherField
})
.ToList();