Код: Выделить всё
// the query
_repo.Query()
.Select(ProjectionItem.MainProjection);
// elsewhere...
public class ProjectionItem
{
public int Foo { get; set; }
public int Bar { get; set; }
public int YaddaYadda { get; set; }
public static Expression MainProjection
{
get
{
return x => new ProjectionItem
{
Foo = x.Foo,
Bar = x.SomeOtherStuff.AndMoreStuff
.ThisDoesSomething(),
YaddaYadda = x.YouGetTheDrill,
// in reality there's like 80 more columns being mapped
};
}
}
}
public class ProjectionItem
{
public int Foo { get; set; }
public int Bar { get; set; }
public int YaddaYadda { get; set; }
public ProjectionItem(FooBarObject x)
{
Foo = x.Foo;
Bar = x.SomeOtherStuff.AndMoreStuff
.ThisDoesSomething();
}
public static Expression MainProjection
{
get
{
return x => new ProjectionItem(x)
{
YaddaYadda = x.YouGetTheDrill,
};
}
}
public static Expression NewProjection
{
get
{
return x => new ProjectionItem(x)
{
YaddaYadda = x.YouGetTheDrill + 1,
};
}
}
}
< /code>
Но это привело к этому исключению: < /p>
system.notsupportedException: «только без параметрических конструкторов и инициализаторов поддерживаются в LINQ для объектов. < /p>
< /blockquote>
strong>. использует структуру Entity для взаимодействия с базой данных
Подробнее здесь: https://stackoverflow.com/questions/796 ... -framework