List<Tuan.Model.Products> Plst = GetList();
Dictionary<int, int> bought = GetDic() var query = from dic in bought
             join p in Plst.AsEnumerable()
             on dic.Key equals p.ProductID
             select p.Bought = dic.Value; //赋值这样写行不?下一步怎么做了?
           一定要用linq的写法!

解决方案 »

  1.   

    select new {Bought = dic.Value }
      

  2.   


    现在我不是要查询值,而是要更新List<T>里面的值
      

  3.   

    join on 这样不是集合查询了
    select你那种是可以赋值的
      

  4.   

     class Program
        {
            static int[] i1 = { 11, 22, 33, 44, 4 };
            static int[] i2 = { 9, 8, 7, 6, 5 };
            static void Main(string[] args)
            {
                Dictionary<int, int> dic = new Dictionary<int, int>();
                for (int i = 0; i < i1.Length; i++)
                {
                    dic.Add(i1[i], i2[i]);
                }
                List<People> li = new List<People>();
                People people1 = new People();
                people1.ID = 11;
                li.Add(people1);            People people2 = new People();
                people2.ID = 33;
                li.Add(people2);            var query = from d in dic join l in li.AsEnumerable() on d.Key equals l.ID select l.Count = d.Value;
                Array.ForEach(query.ToArray(), n => Console.WriteLine(n));            Console.Read();
            }        public class People
            {
                public int ID;
                public int Count;
            }
        }
    结果:
    9
    7