私は私のEF4プロジェクト内に2つのテーブルがあります。彼らは参加していません。私のMVCモデルにlinqグループのクエリ
CustomerTable のCustomerId ConsumerName AllowEmails
PurchaseTable PurchaseId のCustomerId PurchaseDate ......
私は、彼らが内のトランザクションを持っていたときにグループ化された顧客を返すされてやろうとしていますPurchaseTable。彼らが購入していないか、または消費者IDがCustomerIdにまだ追加されていない場合、私はそれらを無視したい。
私は
var query = from t in ctx.PurchaseTable
join j in ctx.CustomerTable on t.CustomerId equals
j.ConsumerId
where j.AllowEmails==true
group t by new
{
t.CustomerId,
j.ConsumerName,
j.EmailAddress
}
into g
select new {Customer = g.Key};
は、今私はちょうどforeachループを実行し、リストに結果を追加することができますが、私はそれのようにリストに追加する素敵なことだと思いたいように私が働いているLINQクエリを持っていますクエリの一部。
これはこれまで私が持っていたものです。
var data = (from t in ctx.PurchaseTable
join j in ctx.CustomerTable on t.CustomerId equals
j.CustomerId
where j.AllowEmails== true
//group t by new //group t by new ConsumerModel
group t by new CustomerModel
{
CustomerName= t.CustomerName,
Email= j.EmailAddress,
CustomerId = j.CustomerId
}
into g select g);
誰かが私の質問を正しい方向に向けることができますか?
ありがとうございました!
Doh !!!!私は近くにいた。ご協力いただきありがとうございます :) –