私個人のショッピングカートにある全ての学校のプログラムや製品を引っ張るこのジョイン・クエリを持っている:結果がNULLであっても結果を取得するlinqラムダ結合クエリを作成するにはどうすればよいですか?
//this pulls all items the user purchased
var poop = Context.Query<Cart>().Where(x => x.UserId == currentUserId && x.Status == "Archived")
.Select(
p => new
{
p.ItemId,
p.TypeId,
p.PurchaseDate
})
//This get the media type name of the cart items
.Join(
Context.Query<MediaType>(),
t => new {t.TypeId},
m => new {TypeId = m.Id},
(t, m) => new
{
t.ItemId,
t.TypeId,
t.PurchaseDate,
m.TypeName
}).OrderBy(d => d.PurchaseDate)
//Now i need specifics of the items like name, sku, etc. StartDate will be null for items that are products, but contains DateTime for items that are programs.
.Join(
Context.Query<ProgramProductView>(),
e => new {e.ItemId, e.TypeId},
prog => new {ItemId = prog.Id, prog.TypeId},
(e, prog) => new
{
e.ItemId,
e.TypeId,
e.PurchaseDate,
e.TypeName,
prog.FullName,
prog.StartDate,
prog.Sku,
prog.Closed
}).OrderBy(d => d.PurchaseDate);
prog.StartDateが製品にヌルであるので、それがクラッシュするところがあるので、右。私はを入手することができませんエラー。
ヌル可能フィールドを許可するには、参加する方法がありますか?ラムダを使用しているのは、読みやすく、きれいなので簡単です。
'(DateTime?)prog.StartDate'を試してください – MaKCbIMKo
* facepalm ....簡単なことでした。ありがとう。あなたはそれを答えにすることができますか? – NeoSketo
これを答えに入れてください。 – MaKCbIMKo