![](/img/trans.png)
[英]How to join aspnet_membership and aspnet_users using linq?
[英]How to get the data from aspnet_Membership, aspnet_Users and aspnet_UsersInRoles in aspnetDB?
我想問一下如何分別在aspnet_Membership和aspnet_Users中獲取數據? 甚至是C#中的aspnet_UsersInRoles? 當我從這些aspnet表中獲取數據時,我將使用LINQ語句。
非常感謝。
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;
}
}
}
成員身份,userinrole表的方式相同
答案很復雜。
您可以使用Linq映射所有這些表並直接查詢它們。
許多領域都是分散的。 您將需要創建將許多表鏈接在一起的視圖。
某些信息(如密碼)將被加密。 並且您必須使用Membership API進行大多數操作(在讀取數據之外)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.