How can I check if a value exists in a list using C#
Posted
by
Samantha J
on Stack Overflow
See other posts from Stack Overflow
or by Samantha J
Published on 2013-10-26T09:42:26Z
Indexed on
2013/10/26
9:53 UTC
Read the original article
Hit count: 238
I have the following code that gives me a list of id and names from the new ASP.NET MVC5 Identity:
var identityStore = new IdentityStore();
var users =
(
from user in identityStore.DbContext.Set<User>()
select new
{
id = user.Id,
name = user.UserName
}
);
How could I modify this so that it allows me to check if a UserName exists?
Here's the user class:
public class User : IUser
{
public User();
public User(string userName);
[Key]
public string Id { get; set; }
public virtual ICollection<UserLogin> Logins { get; set; }
public virtual UserManagement Management { get; set; }
public virtual ICollection<UserRole> Roles { get; set; }
public string UserName { get; set; }
}
© Stack Overflow or respective owner