【发布时间】:2018-12-01 15:10:40
【问题描述】:
在 .Net 教程中(在 udemy 和一些网站中)我看到他们声明了用于定义模型之间关系的 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; }
}
}
【问题讨论】:
-
EF 会使用 convections 来生成“releations”,如果你不明确声明它们,看看learnentityframeworkcore.com/conventions
标签: c# .net-core entity-framework-core ef-core-2.0