0
使用實體框架處理我的第一個MVC5項目。當我加載用戶並嘗試訪問他們所在的角色時,延遲加載正嘗試從AspNetUserAspNetRoles加載。該表實際上命名爲AspNetUserRoles,我認爲它是默認的,並且在向用戶添加角色時工作正常。我的DBA爲我設置了最初的模型集合,並且正在參加一個會議。我想我可能會在我的DBContext中丟失一些東西,但一小時後我仍然在尋找一個很好的參考來解決我的問題。無效的對象名稱'dbo.AspNetUserAspNetRoles'
這是我的AspNetUser模型。我消除了一些其他的關係,以節省空間
public partial class AspNetUser : IBusinessObject
{
public AspNetUser()
{
this.AspNetRoles = new List<AspNetRole>();
}
public string Id { get; set; }
public string UserName { get; set; }
public string PasswordHash { get; set; }
public string SecurityStamp { get; set; }
public string Discriminator { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public System.DateTime CreatedOn { get; set; }
public System.DateTime UpdatedOn { get; set; }
public string CreatedByUserId { get; set; }
public bool IsDeleted { get; set; }
public string ResetPasswordKey { get; set; }
public Nullable<System.DateTime> ResetPasswordKeyExpiration { get; set; }
public virtual ICollection<AspNetRole> AspNetRoles { get; set; }
public void SoftDelete(bool reverse = false)
{
IsDeleted = !reverse;
}
}
這裏是AspNetRole模型
public partial class AspNetRole : INameable, IBusinessObject
{
public AspNetRole()
{
this.AspNetUsers = new List<AspNetUser>();
}
public string Id { get; set; }
public string Name { get; set; }
public virtual ICollection<AspNetUser> AspNetUsers { get; set; }
}
,這裏是我的DbContext
public partial class SdContext : DbContext
{
static SdContext()
{
Database.SetInitializer<SdContext>(null);
}
public SdContext()
: base("SdConnection")
{
}
public DbSet<Cluster> Clusters { get; set; }
public DbSet<CoLabDate> CoLabDates { get; set; }
public DbSet<CoLabLocation> CoLabLocations { get; set; }
public DbSet<CoLab> CoLabs { get; set; }
public DbSet<CoLabType> CoLabTypes { get; set; }
public DbSet<Contact> Contacts { get; set; }
public DbSet<Document> Documents { get; set; }
public DbSet<Organization> Organizations { get; set; }
public DbSet<Participant> Participants { get; set; }
public DbSet<Project> Projects { get; set; }
public DbSet<Statement> Statements { get; set; }
public DbSet<TriggeringQuestion> TriggeringQuestions { get; set; }
public DbSet<VoteAction> VoteActions { get; set; }
public DbSet<Vote> Votes { get; set; }
public DbSet<VoteType> VoteTypes { get; set; }
public DbSet<AspNetUser> AspNetUser { get; set; }
public DbSet<AspNetRole> AspNetRole { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new ClusterMap());
modelBuilder.Configurations.Add(new CoLabDateMap());
modelBuilder.Configurations.Add(new CoLabLocationMap());
modelBuilder.Configurations.Add(new CoLabMap());
modelBuilder.Configurations.Add(new CoLabTypeMap());
modelBuilder.Configurations.Add(new ContactMap());
modelBuilder.Configurations.Add(new DocumentMap());
modelBuilder.Configurations.Add(new OrganizationMap());
modelBuilder.Configurations.Add(new ParticipantMap());
modelBuilder.Configurations.Add(new ProjectMap());
modelBuilder.Configurations.Add(new StatementMap());
modelBuilder.Configurations.Add(new TriggeringQuestionMap());
modelBuilder.Configurations.Add(new VoteActionMap());
modelBuilder.Configurations.Add(new VoteMap());
modelBuilder.Configurations.Add(new VoteTypeMap());
}
}
請編輯您的previos答案併發布整個解決方案並刪除此答案,以使其他人更容易理解解決方案。如果它解決了您的問題,請將您的答案標記爲已接受。 –
相反,我刪除了以前,因爲這是整個解決方案。直到48小時後,我才能將其標記爲已接受。 – Tom