[英]How to use a table like a reference table in Entity Framework Core
[英]Entity Framework Core How to make a Reference table for a model
我一直在使用SQL表來引用靜態數據,例如,在我的一個應用程序中,技術人員與客戶表具有一對多關系。
基本上,我想在SQL中執行的操作是這樣,因此,與處理字符串不同,我將ints作為字節或tinyint處理,這在磁盤上占用的空間較小,因為客戶端始終是靜態的,很少添加新的。
| Technicians | | Clients | | ClientsRef |
| Id | | Id | ClientRefId | TechnicianId | | Id | Name |
我的問題是要在EF Core 2.2中執行此操作,如何創建此靜態數據? 我讀過有關使用枚舉的信息,但是之后如何在SQL Server中訪問該數據呢?
public class Technician
{
int Id { get;set; }
}
public class Client
{
int Id { get;set; }
int Technicianid { get; set; }
}
這個:
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; }
}
應該是您所需要的。 模型中不需要任何其他表或鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.