EntityFramework 6.2を使用して、各エンティティのコレクションとネストされたコレクションのフィールドを投影したいと思います。6.2蛇のコードのような動的クエリを使用しています
Students.Select("new (Name,Family,new(Category.Name) as Category)");
それは働いていましたが、私はコレクションでそれをしたいときにそれはエラーがスローされている
Students.Select("new (Name,Family,new(Courses.Name,Courses.UnitName) as Courses)");
私は、コードを返すように結果を返します
Students.Select(std=>new{
std.Name,
Category=new{std.Category.Name},
Courses=std.Courses.Select(co=>new{
co.Name,co.UnitName
})}) ;
あなたが私と一緒に何かアイデアを共有してください
System.Linq.Dynamic
行うことはできません。 System.Linq.Dynamic.Core
(ライブラリのより高度なフォーク)で可能です。
動的ではない方法で記述したクエリと同等です。
var q = Students.Select("new (Name, Category.Name as Category, Courses.Select(new (Name, UnitName)) as Courses)");
あなたが探していたのは単にCourses.Select(new (field1, field2)) as SomeAlias