我有兩個DataTables,項目和它的組。我有一個LINQ查詢通過加入2個表來獲取項目名稱和它的組名。加入Linq查詢DataTable和結果DataView
EnumerableRowCollection<DataRow> dvquery = (from item in Items.AsEnumerable()
join grp in groups.AsEnumerable()
on item.Field<byte>("Group_ID") equals grp.Field<byte>("ID")
into item_grp_join
from itemgrp in item_grp_join
select new
{
ItemName = (string)led.Field<string>("Name"),
GName = (string)itemgrp.Field<string>("Name"),
});
DataView dv = dvquery.AsDataView();
但是我收到編譯時錯誤作爲
無法隱式轉換類型「System.Collections.Generic.IEnumerable」到「System.Data.EnumerableRowCollection」。存在明顯的轉換(您是否缺少演員?)
如何解決此錯誤?我可以很容易地將查詢結果轉換爲列表,但我只需要一個數據視圖,因爲我可以將它作爲數據源提供給網格。
任何幫助表示讚賞。 感謝
經歷了同樣的問題,感謝張貼。 – Pat