2014-11-11 2 views
1

사용자 용 UserController 및 Views를 비계하려고 노력하고 있습니다. 처음에는 컨트롤러를 스 캐 폴딩 할 때 "형식 당 여러 개체 세트가 지원되지 않습니다."라는 오류가 표시됩니다. (이것은 ApplicationUser 및 User와 관련이 있습니다.) Areas/Admin에서 컨트롤러를 비계하려고합니다.형식 당 여러 개체 집합

그런 다음 StackOverflow에서 ApplicationUser 클래스의 이름을 User로 변경하여 많은 오류가 발생했습니다. 나는 ApplicationUser에 대한 모든 참조를 User로 변경했지만 여전히 동일한 오류가 발생합니다. 다시 ApplicationUser로 변경하고, 그것을 다시 스캐 폴딩하려고 시도했습니다 (컨트롤러에서 Area/Admin 대신). 그것은 응용 프로그램을 실행하기 전까지는 효과가있는 것처럼 보였습니다. 그것은 나에게 똑같은 오류를 준다.

using System.Data.Entity; 
using System.Security.Claims; 
using System.Threading.Tasks; 
using Microsoft.AspNet.Identity; 
using Microsoft.AspNet.Identity.EntityFramework; 

namespace ImpHer.Models 
{ 
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. 
    public class ApplicationUser : IdentityUser 
    { 
     public string PostalCode { get; set; } 
     public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) 
     { 
      // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 
      var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); 
      // Add custom user claims here 
      return userIdentity; 
     } 
    } 

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
    { 
     public ApplicationDbContext() 
      : base("DefaultConnection", throwIfV1Schema: false) 
     { 
     } 

     public static ApplicationDbContext Create() 
     { 
      return new ApplicationDbContext(); 
     } 

     public System.Data.Entity.DbSet<ImpHer.Models.Project> Projects { get; set; } 

     public System.Data.Entity.DbSet<ImpHer.Models.Category> Categories { get; set; } 

     public System.Data.Entity.DbSet<ImpHer.Models.ApplicationUser> ApplicationUsers { get; set; } 
    } 
} 

이것은 IdentityModels.cs입니다. 누가 도와 드릴 수 있습니까?

+0

어디에서 예외가 발생합니까? –

+0

선택한 코드 생성기를 실행하는 동안 오류가 발생했습니다 : ''Models.ApplicationUser '에 대한 메타 데이터를 검색 할 수 없습니다. 유형 당 여러 오브젝트 세트는 지원되지 않습니다. 개체 집합 'ApplicationUsers'및 'Users'모두 'Models.ApplicationUser'형식의 인스턴스를 포함 할 수 있습니다. –

답변

1

나는 EntityModels.cs에서 public System.Data.Entity.DbSet<ImpHer.Models.ApplicationUser> ApplicationUsers {get;set;}을 삭제했습니다. 그런 다음 UsersController.cs에서 ApplicationUser를 모든 사용자로 바꿉니다.

이것은 트릭을 만들었습니다!

+1

오직 필요한 부분은 스캐 폴드가 추가 한'DbSet'을 제거하는 것이 었습니다. 이것은'ApplicationDservice'가'IdentityDbContext <> '에 대한 타입 인자이기 때문에 이미'DbSet'을 가지고 있다는 것을 인식하지 못하는 비계의 버그 인 것 같습니다. –

+0

@ChrisPratt 아, 알았어요. 그래서'ApplicationUser'를 사용해야한다고 말하는 겁니까? 아니면 차이가 있습니까? –

+1

실제로 차이점이 없습니다. 나는'ApplicationUser'가 무분별하게 느껴지기 때문에 광산을'User'로 변경했습니다. 그 단계는 다른 사람이 같은 문제로이 답을 찾지 못했을 때 문제를 해결할 필요가 없다는 것을 지적하고 있습니다. –