I have a class called UserInfo that contains details about a given user.
There are several places in code where the data might be queried and I'd like to have a single function to fill the UserInfo object with the corresponding data from the Linq Query.
var userData = dc.Users.Where(λ => (λ.Login == username) && λ.Active)
.Select(λ => new { λ.ID, Salt = λ.Seasonings.Single().Salt, λ.Login, λ.PassHash, λ.Admin, λ.Trusted, λ.E_mail, λ.Name, λ.Phone, λ.Note, λ.RegistrationDate }).SingleOrDefault();
string tmppass = generatePassHash(password, userData.Salt);
if (userData.PassHash.Trim() == tmppass.Trim())
{
ID = userData.ID;
// Here is the stuff i'd like to move to a function
_user._id = userData.ID;
_user._userState = State.NotAuthorized;
_user._username = userData.Login;
_user._name = userData.Name;
_user._email = userData.E_mail;
_user._phone = userData.Phone;
_user._notes = userData.Note;
...
}
How do I properly set up a function to accept this anonymous type as an argument? Do I need to declare a new interface or is there a simpler way?
Thanks for the help!
PS- sorry for the excessive underscores, nested classes make things a bit messy.