在.NET教程(在UDMEY和一些站点)中,我看到他们声明了用于定义模型之间关系的FLUENT API。
我试着在fluent api中创建模型而不是定义关系,看来迁移是有效的,我检查了mysql外键的定义也很好。
我只想知道,当我们真正需要用fluent api定义模型之间的关系时(
OnModelCreating
)
我的模型:
using System.Collections.Generic;
namespace CRSApp.API.Models
{
public class UserGroup
{
public int Id { get; set; }
public string GroupName { get; set; }
ICollection<User> Users { get; set; }
ICollection<UserGroupDetail> Details {get; set;}
}
}
namespace CRSApp.API.Models
{
public class UserGroupDetail
{
public int Id { get; set; }
public int UserGroupId { get; set; }
public int ModuleComponentId { get; set; }
public UserGroup UserGroup { get; set; }
public ModuleComponent ModuleComponent { get; set; }
}
}