bugfix> c# > 投稿

私の質問は、IDの結合内で、IDを持つ別の列を追加することは可能ですか? これは私がやろうとしていることです:

私のインデックス:

var orders= db.Orders.ToList();
var colers = db.Colors.ToList();
var result = (from c in orders
             join st in colers on c.ID_Orders equals st.id into table1
             select new OrderWithColorsViewModel { order =c, colers = table1.ToList() 
}).ToList();
return View(result);

私のクラス:

public partial class Orders
{
    public int ID_Orders { get; set; }
    public Nullable<System.DateTime> Data_Registo { get; set; }
    public string Num_Encomenda { get; set; }
    public string Ref_Cliente { get; set; }
}
public partial class Colors
{
    public int ID_Orders { get; set; }
    public int ID_Line_Color { get; set; }
    public string Color{ get; set; }
}
public partial class Quantities
{
    public int ID_Orders { get; set; }
    public int ID_Line_Color { get; set; }
    public int quantity{ get; set; }
}

私が今学んでいることのうち、私は私の参加からこれを持っています:

そして:

しかし、私が欲しいもの(私は思う):

私が考えるのが間違っているなら、私を訂正してください、ありがとう

回答 1 件
  • 私はそれを必要とする人々のために私の解決策をここに残します

           var result1 = (from o in order
                           join c in coler
                              on o.ID_Programa equals c.ID_Programa into co
                           group new { o, co } by o.ID_Programa into g
                           from i in g
                           select new { order = i.o, colors = i.co }).ToList();
            var result2 = (from r1 in result1
                           from c in r1.colors
                           join q in quant
                             on new { orderId = c.ID_Programa, colorlineId = c.ID_Linha_Cor } equals new { orderId = q.ID_Programa, colorlineId = q.ID_Linha_Cor } into p1
                           from p in p1
                           join s in statu
                             on new { orderId = p.ID_Programa, colorlineId = p.ID_Linha_Cor } equals new { orderId = s.ID_Programa, colorlineId = s.ID_Linha_Cor } into q
                           group new ColorsAndQuantities { coler = c, quant = p1.ToList(), status = q.ToList() } by c.ID_Programa).ToList();
            var result = (from r1 in result1
                          join m in fabric
                            on r1.order.ID_Programa equals m.ID_Programa into t
                            from t1 in t
                          join r2 in result2
                             on t1.ID_Programa equals r2.Key
                          select new OrdersColorsViewModel
                          {
                              order = r1.order,
                              malhas = t1,
                              colers = r2.ToList()
                          }).ToList();
    
    

あなたの答え