var userData = (from u in DB.user_data
join p in DB.users on u.userid equals p.userid
join s in DB.roles on p.roleid equals s.roleid
where u.deptid == 24
select new UserData()
{
userId = u.id,
RoleName = s.Name,
CreateDate = u.Create_date,
Active = u.Active,
ValidTokens = GetTokencount(-- userdata --) -- how to pass current userdata object here
}).ToList();
following is the global method from which I get the available taken counts for a user based on a logic
public int GetTokencount(UserData objUserData)
{
// code to get count goes here
}
Simply put, you can’t. When you’re in the object initializer, the current
UserDataobject hasn’t been initialized yet, so you cannot reference it.Instead, you can loop through the collection after it’s been created to set your
ValidTokensproperty on eachUserDatainstance.