[英]Get a Property value in a BindingSource LINQ
Below is my bindingSource. 以下是我的bindingSource。
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 };
I want to get the UserID of the current record. 我想获取当前记录的UserID。
var userRecord = pics_Data_HistoryBSForCounts.Current;
I get the current records as a string. 我以字符串形式获取当前记录。 Is there any way to get a property value?
有什么方法可以获取属性值?
Thanks! 谢谢!
BindingSource.Current
is an object
. BindingSource.Current
是一个object
。 You can cast it to type T of you IQueryable<T>
(dataCtx.Pics_Data_Histories). 您可以将其强制转换为
IQueryable<T>
类型(dataCtx.Pics_Data_Histories)。 But that is an anonymous type, so it is easier to use a named type for it (otherwise you can only use Reflection to extract a property value). 但这是一个匿名类型,因此更容易使用命名类型(否则只能使用Reflection提取属性值)。
So, suppose you have a class UserData
(with UserName
, Count
and UserID
). 因此,假设您有一个类
UserData
(具有UserName
, Count
和UserID
)。 The select
part of your query is: 查询的
select
部分是:
select new UserData { UserName = grouped.Key.Trim(), ...
And the cast: 和演员:
var userRecord = (UserData)pics_Data_HistoryBSForCounts.Current;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.