私はこれで混乱していると思います。私のデータベースは次のようになります。
Locations [root]
Inspections [level1]
InspectionItems [level2]
InspectionReadings [level3]
Areas [level1]
Inspections [level2]
InspectionItems [level3]
InspectionReadings [level4]
各テーブルはGuidによって前のテーブルにリンクされており、Inspectionsテーブルにはnull許容のAreaIDがあるため、Locationsの直接の子になることができます。
必要なのは
for each Location
{take all InspectionReadings entities
where location == location
sort date descending
return the top Entity details}
add the Location details and the InspectionReading details into a new table
return new table
結果は、場所のリストとそれらの最新の検査読み取り日を含むデータグリッドになるはずです。各場所は1回だけ表示されます。
私が管理しているのは(これは私のDomainService.csにあります)
public IQueryable<LocationStatusList> GetLocationStatus()
{
var status = (from a in ObjectContext.Locations
from b in ObjectContext.InspectionReadings
orderby b.DateTaken descending, a.Name
select new LocationStatusList()
{
ID = b.ID,
LocationName = a.Name,
LastInspectionDate = b.DateTaken ?? DateTime.MinValue, // the data is nullable so it needs a value to return in that case
StatusNumber = b.Status ?? -1 // the data is nullable so it needs a value to return in that case
});
return status;
}
これは、InspectionItemsエンティティ全体を関連する場所とともに返します。試しましたが、必要なことを実行する方法が見つかりません。
DomainServiceクラスでこのためのすべてのコードを実行したいのですが、現時点で考えられる唯一の方法は、ビューモデルからパラメーターとして各場所の名前をクエリに指定し、単一のエンティティを返し、新しいリストを作成して追加することです。各単一エンティティ。
確かに、これはすべてLINQクエリで実行できますか?