0

Below is my 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.

var userRecord = pics_Data_HistoryBSForCounts.Current;

I get the current records as a string. Is there any way to get a property value?

Thanks!

ABCD
  • 897
  • 16
  • 38

1 Answers1

0

BindingSource.Current is an object. You can cast it to type T of you 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).

So, suppose you have a class UserData (with UserName, Count and UserID). The select part of your query is:

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

And the cast:

var userRecord = (UserData)pics_Data_HistoryBSForCounts.Current;
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291