简体   繁体   English

实体框架核心如何为模型创建参考表

[英]Entity Framework Core How to make a Reference table for a model

I have been using SQL tables for referencing static data, for example in one of my apps a technician has a one-to-many relation with a clients table. 我一直在使用SQL表来引用静态数据,例如,在我的一个应用程序中,技术人员与客户表具有一对多关系。

Basically what I want to do in SQL is this, so instead of dealing with strings I deal with ints as byte or tinyint which takes less size on disk since Clients are always static and it's rare to add new ones. 基本上,我想在SQL中执行的操作是这样,因此,与处理字符串不同,我将ints作为字节或tinyint处理,这在磁盘上占用的空间较小,因为客户端始终是静态的,很少添加新的。

 | Technicians |    |            Clients              |   | ClientsRef |
 |     Id      |    | Id | ClientRefId | TechnicianId |   | Id  | Name |

My problem is to do this in EF Core 2.2, how do I create this static data? 我的问题是要在EF Core 2.2中执行此操作,如何创建此静态数据? I read about using enum but how can I access that data in SQL Server after? 我读过有关使用枚举的信息,但是之后如何在SQL Server中访问该数据呢?

public class Technician
{
    int Id { get;set; }
}

public class Client
{
    int Id { get;set; }
    int Technicianid { get; set; }
}   

This: 这个:

public class Technician
{
    int Id { get;set; }
}

public class Client
{
    int Id { get; set; }
    int TechnicianId { get; set; }
    public virtual Technician Technician {get; set;}
    public string Name { get; set; }
}

Should be all you need. 应该是您所需要的。 There's no need for any other tables or keys in the model. 模型中不需要任何其他表或键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM