Грешка при Relation
Здравейте, колеги правия едно приложение с Users и Posts и искам да добавя Likes на всеки Post и един User да може да лайква по един път.
Но като мигрирам базата ми дава грешка. Някой има ли идея защо не става? Благодаря предварително.
Unable to determine the relationship represented by navigation property 'Topic.ApplicationUsers' of type 'List<ApplicationUser>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Blog.Models;
namespace Forum.Models
{
public class Post
{
public Post()
{
this.Comments = new List<Comment>();
}
[Key]
public int PostId { get; set; }
public int LikesCount { get; set; }
public List<ApplicationUser> ApplicationUsers { get; set; }
[Required]
public virtual string Title { get; set; }
[ForeignKey("Category")]
public int CategoryId { get; set; }
public Category Category { get; set; }
[Required]
public string Description { get; set; }
[Display(Name = "Create Date")]
public DateTime CreateDate { get; set; }
[Display(Name = "Last Updated Date")]
public DateTime LastUpdatedDate { get; set; }
public string AuthorId { get; set; }
public virtual ApplicationUser Author { get; set; }
public List<Comment> Comments { get; set; }
[NotMapped]
[Display(Name = "Number Comments")]
public int NumberComments => Comments.Count;
}
}
using System.Collections.Generic;
using Forum.Models;
using Microsoft.AspNetCore.Identity;
namespace Blog.Models
{
public class ApplicationUser : IdentityUser
{
public ApplicationUser()
{
this.LikePosts = new List<Post>();
}
public string FullName { get; set; }
public ICollection<Post> LikePosts { get; set; }
}
}