设计模型对我来说总是很痛苦。我的进步方式是:
我告诉没有table2class转换的原因是:我真的需要了解如何在mysql /手动上做到这一点。我是初学者,每次我把手放在这个区域时我都很难受。
考虑为员工和公司保存评级的示例。员工可以评价自己,而且有几名员工可以为公司评分。所以数据库变成了:
我们如何为此方案设计模型。我真的不明白。以下是想要的模型。
[Table("employee")]
public class Employee
{
[Key]
public int id { get; set; }
...
public List<Rating> ratings { get; set; }
}
[Table("company")]
public class Company
{
[Key]
public int id { get; set; }
...
List of List of Rating which can seperate by each employee
what should come here
}
我们如何设计模型来完成employee_rating和employee_company_rating。如果我完全错了,请指出。
还为我提供了一些关于如何进行/思考模型设计的教程
答案 0 :(得分:1)
这是一种以数据为中心的方法,并且有足够的资源。您可能还想考虑一种代码首先鼓励的面向对象的方法。 https://softwareengineering.stackexchange.com/questions/264379/code-first-vs-database-first
至于您当前的问题,根据您的描述,您需要另一个跨越员工和公司的课程:
public class CompanyEmployee
{
public int CompanyId { get; set; }
public int EmployeeId { get; set; }
...
public List<Rating> CompanyRatings { get; set; }
}
您可以向公司添加员工列表以进行导航。此外,如果类和表名相同,则不需要表注释。