var componentListQuery = conn.component.Where(m => componentProdIDList.Contains(m.ProdID)).OrderBy(m => m.ProdID).ToList();这个排序无效的。不知道什么原因。谁知道是怎那么回事啊。谢谢!
目测这行代码没毛病,你看下翻译成SQL是怎样的就了然了
测试ok:
Conn conn = new Conn();
conn.component = new List<Component>();
List<Component> comp = new List<Component> {
new Component { ProdID = 1 },
new Component { ProdID = 2 },
new Component { ProdID = 3 }
};
conn.component.AddRange(comp);
var componentProdIDList = new List<int> { 2, 1, 3, 4 };
var componentListQuery = conn.component.Where(m => componentProdIDList.Contains(m.ProdID)).OrderBy(m => m.ProdID).ToList();
var arr = from o in componentListQuery select o.ProdID;
string s = string.Join(",", arr);
Console.WriteLine(s);
谢谢你哈。我翻译sql看看到底怎么回事。