2012-12-02 61 views
0

下面是我的bindingSource。在BindingSource中獲取屬性值LINQ

pics_Data_HistoryBSForCounts.DataSource = from dh in dataCtx.Pics_Data_Histories 
                 join ui in dataCtx.User_Infos on dh.User_Id equals ui.user_id into ui_dh 
                 from ui_dh1 in ui_dh.DefaultIfEmpty() 
                 where dh.Changed_Date >= fromDate && dh.Changed_Date <= toDate 
                 group ui_dh1 by ui_dh1.user_name into grouped 
                 select new { UserName = grouped.Key.Trim(), Count = grouped.Count(a => a.user_name != null), UserID = grouped.FirstOrDefault().user_id }; 

我想獲取當前記錄的用戶標識。

var userRecord = pics_Data_HistoryBSForCounts.Current; 

我以字符串形式獲取當前記錄。有沒有辦法獲得物業價值?

謝謝!

回答

0

BindingSource.Currentobject。你可以把它轉換成你的類型T IQueryable<T>(dataCtx.Pics_Data_Histories)。但是這是一個匿名類型,因此使用它的命名類型更容易(否則只能使用Reflection來提取屬性值)。

所以,假設你有一個類UserData(與UserName,CountUserID)。您查詢的select部分是:

select new UserData { UserName = grouped.Key.Trim(), ... 

和演員:

var userRecord = (UserData)pics_Data_HistoryBSForCounts.Current;