WPF entity Framework load specified data to List when Window is loaded

88 views Asked by At

I want to load the UserName from my table (who match the UserName in Settings.Default) ToList. Please see code below:

private void LoadUserData()
    {
        var item = context.Users.FirstOrDefault(w => w.UserName == Properties.Settings.Default.UserName).ToList();
        userList = item;
    }

It says: User has no definition for ToList.

how can i solve this? Any idear?

1

There are 1 answers

4
Nawed Nabi Zada On BEST ANSWER

Remove the ToList() at the end of your statement.

ToList is to create a List<T> from IEnumerable<T>.

In case you have more users with the same UserName (hopefully not) you can get a list of those user by:

var item = context.Users.Where(w => w.UserName == Properties.Settings.Default.UserName).ToList();