Reputation: 31
I wanna ask how to get the datas in aspnet_Membership and aspnet_Users separately?? and even aspnet_UsersInRoles in C#? I'll be using LINQ statement when I get the data from these aspnet tables.
Thank you so much.
Upvotes: 1
Views: 826
Reputation: 76
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection") // web.config
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
}
public class UserData
{
private static List<UserProfile> _userList;
public static List<UserProfile> userList
{
get
{
if (_userList == null)
{
UsersContext db = new UsersContext();
_userList = db.UserProfiles.SqlQuery("select * from dbo.UserProfile").ToList();
}
return _userList;
}
set
{
_userList = value;
}
}
}
same way for membership, userinrole table
Upvotes: 2
Reputation: 32500
The answer is complex.
You can map all those tables with Linq and query them directly.
Many of the fields are scattered. You will want to create Views that link many of the tables together.
Some information (like passwords) will be encrypted. And most actions (outside of reading data) you'll have to make using the Membership API.
Upvotes: 1