Код: Выделить всё
// 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 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: 'только конструкторы без параметра и инициализаторы и инициализаторы. и использует структуру объекта для взаимодействия с базой данных
Подробнее здесь: https://stackoverflow.com/questions/796 ... -framework