私は次のlinqクエリを持っています
public IEnumerable<DealershipWithDealersViewModel> Get(float latitude, float longitude)
{
return from dealer in Db.Dealerships
join i in Db.NearestDealers(latitude, longitude)
on dealer.DealerID equals i.DealerID
select new DealershipWithDealersViewModel
{
DealerID = dealer.DealerID,
Dealer = dealer.Dealer,
DoSales = dealer.DoSales,
DoService = dealer.DoService,
AddressProvinceID = dealer.AddressProvinceID,
AddressLocationID = dealer.AddressLocationID,
Address1 = dealer.Address1,
Address2 = dealer.Address2,
Tel = dealer.Tel,
Fax = dealer.Fax,
MapLat = dealer.MapLat,
MapLong = dealer.MapLong,
Location = dealer.Location.LocationName,
DealerUsers = dealer.DealerUsers
.Select(y => new DealerUserViewModel
{
DealerUserID = y.DealerUserID,
FirstName = y.Firstname,
Surname = y.Surname,
LandLine = y.LandLine,
Email = y.Email,
Position = y.DealerType.DealerPosition
})
};
}
次のエラーが発生し続けますネストされたクエリに適切なキーがありません。ネット上で何も見つかりません。DealerUsersなしで上記をロードすると、期待どおりに機能しますが、ネストされたデータが必要です。ありがとうございました!ちなみに以下は動作します。
public IEnumerable<DealershipWithDealersViewModel> Get(float latitude, float longitude)
{
return from dealer in Db.Dealerships
join i in Db.NearestDealers(latitude, longitude)
on dealer.DealerID equals i.DealerID
select new DealershipWithDealersViewModel
{
DealerID = dealer.DealerID,
Dealer = dealer.Dealer,
DoSales = dealer.DoSales,
DoService = dealer.DoService,
AddressProvinceID = dealer.AddressProvinceID,
AddressLocationID = dealer.AddressLocationID,
Address1 = dealer.Address1,
Address2 = dealer.Address2,
Tel = dealer.Tel,
Fax = dealer.Fax,
MapLat = dealer.MapLat,
MapLong = dealer.MapLong,
Location = dealer.Location.LocationName
};
}
アップデート
これも機能します。
return Db.Dealerships.Select(x => new DealershipWithDealersViewModel
{
DealerID = x.DealerID,
Dealer = x.Dealer,
DoSales = x.DoSales,
DoService = x.DoService,
AddressProvinceID = x.AddressProvinceID,
AddressLocationID = x.AddressLocationID,
Address1 = x.Address1,
Address2 = x.Address2,
Tel = x.Tel,
Fax = x.Fax,
MapLat = x.MapLat,
MapLong = x.MapLong,
Location = x.Location.Location1,
DealerUsers = x.DealerUsers.Select(y => new DealerUserViewModel
{
DealerUserID = y.DealerUserID,
FirstName = y.Firstname,
Surname = y.Surname,
LandLine = y.LandLine,
Email = y.Email,
Position = y.DealerType.DealerType1
})
});