在linq中一次显示两个表数据

时间:2019-04-13 22:05:43

标签: c# entity-framework linq

我想一次显示两个表信息。

List<int> order_track = db.Order_Trackings.Where(e => e.UID == id).Select(q => q.ID).ToList();
            if (order_track == null)
            {
                var rate = db.Ratings.OrderByDescending(e => e.Rate).Take(5);
            }
          List<int> fidList = db.OrderFoods.Where(q => order_track.Contains(q.OID)).Select(q => q.FID).ToList();
            var qs = (from x in fidList
                      group x by x into g
                      let count = g.Count()
                      orderby count descending
                      select new { KEY = g.Key });

            if (order_track.Count == 2)
            {
                var one = qs;
                List<int> idList = new List<int>();
                foreach (var val in one)
                {
                    idList.Add(val.KEY);
                }
                var food = db.Foods.Where(q => idList.Contains(q.ID));

                var rate = db.Ratings.OrderByDescending(e => e.Rate).FirstorDefault();
                return Request.CreateResponse(HttpStatusCode.OK, rate);

我想做这样的事情,希望您提前了解我要实现的目标。

var food = db.Foods.Where(q => idList.Contains(q.ID)&&db.Ratings.OrderByDescending(e => e.Rate).FirstorDefault());
return Request.CreateResponse(HttpStatusCode.OK, rate);

1 个答案:

答案 0 :(得分:0)

如果要将两个结果合并到一个变量中,那么最简单的方法是创建一个anonymous object,如下所示:

gtk_tree_view_convert_widget_to_bin_window_coords

您还可以创建带有两个gdk_event_get_coords的{​​{1}},然后创建该类的实例,但是如果这是您唯一使用该类的地方,那么我就不会这样做