这个问题我已经有两天了,我还是搞不懂这个问题
这个想法是,我有一个登录的用户,我想添加用户可以将电影添加到收藏列表。
这些是我的模型:
public class User
{
[Key]
public long id { get; set; }
public string? username { get; set; }
public string? email { get; set; }
public string? password { get; set; }
public string? firstName { get; set; }
public string? lastName { get; set; }
public string? address { get; set;}
public ICollection<Favourite> Favourite{ get; set; }
}
public class Movie
{
[Key]
public long id { get; set; }
public string? title { get; set; }
public string? description { get; set; }
public string? gender { get; set; }
public DateTime releaseDate { get; set; }
[NotMapped]
public IFormFile? CoverImage { get; set; }
}
public class Favourite
{
[Key]
public int id { get; set; }
public Movie? Movie { get; set; }
public User? User{ get; set; }
}
任何想法?
帮助学生完成任务
你应该在你的应用程序中使用Fluent API,你将覆盖OnModelCreating方法,并尝试研究Fluent API在模型之间建立多对多关系。这里有一个很好的参考快速理解和应用的想法:https://www.entityframeworktutorial.net/efcore/configure-many-to-many-relationship-in-ef-core.aspx