엔티티 프레임 워크에서 ApplicationUser
과 내 자신의 클래스 사이에 1 : 1 관계가 필요합니다.엔티티 프레임 워크에서 1 : 1 관계
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
/*Realations*/
public virtual ICollection<Comment> Comments { get; set; }
public virtual Posts Post { get; set; }
}
public class Posts : System.Object
{
public Posts()
{
this.PostDate = DateTime.Now;
this.PostViews = 0;
this.PostPic = "d.jpg";
}
[Key]
public int PostID { get; set; }
public string PostName { get; set; }
public string PostSummery { get; set; }
public string PostDesc { get; set; }
public string PostPic { get; set; }
public DateTime PostDate { get; set; }
public int PostViews { get; set; }
public string postMetaKeys { get; set; }
public string PostMetaDesc { get; set; }
public string UserId { get; set; }
[Key, ForeignKey("UserId")]
public virtual ApplicationUser ApplicationUser { get; set; }
public int CategoryID { get; set; }
[Key, ForeignKey("CategoryID")]
public virtual Categories Category { get; set; }
public virtual ICollection<Comment> commnets {get; set;}
}
하지만 Nuget
콘솔 내부의 명령 "추가 마이그레이션 관계"를 쓸 때 나는 예외를 얻고있다 :
나는이 작업을 수행. 유형 'FinalKaminet.Models.ApplicationUser'및 'Models.Posts'간의 관계의 주 단부를 결정할
나는 또한없습니다. 이 연관의 주 끝 부분 인 은 유동적 인 API 또는 데이터 주석 중 하나 인 을 사용하여 명시 적으로 구성되어야합니다.
IdentityModels
내부 코드 아래에 추가 할 수 있지만 다른 오류가 나타났다
:
ApplicationUser_Post_Target :
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>()
.HasOptional(f => f.Post)
.WithRequired(s => s.ApplicationUser);
}
하나 이상의 유효성 검사 오류가 모델 생성 중에 검색된는 : 다중성은 아니다 역할 'ApplicationUser_Post'에 'ApplicationUser_Post_Target'역할 에서 유효합니다. 종속 역할 속성이 주요 속성이 아니기 때문에 종속 역할의 다중도가 상한선은 '*'여야합니다.
무엇이 잘못 되었나요?
표시되는 내용 * 다른 오류 *? –
@AdilMammadov, 업데이트 된 질문. – Farzaneh
'IdentityUser'에는'string' 키가 있습니다. 문제가 될 수 있습니까? –