如何将类映射到数据库表

本文关键字:数据库 映射 | 更新日期: 2023-09-27 17:49:53

我有类,需要使数据表如下类1

   public class EventType
   { 
        public String Id { get; private set; }
        public int Severity { get; set; }
        public EventTypeTemplate Template { get; set; }
        public IDictionary<String, String> Params { get; set; }
        public EventType(string id)
        { 
            Id = id;
            Params = new Dictionary<string, string>();
        }
   }

和第二类

public class EventTypeTemplate
{
     public String Id { get; private set; }
     public int Severity { get; set; }
     public String Title { get; set; }
     public String Description { get; set; }
     public IList<String> Categories { get; private set; }
     public IList<String> Queries { get; private set; }
     public EventTypeTemplate(string id)
     { 
          Id = id;Categories = new List<string>();
          Queries = new List<string>();
     } 
}

对于类1(EventType),我创建表作为表名EventType

Column    type
Id        string
Severity  int

我不知道如何将这些属性添加到表列名和类型

public EventTypeTemplate Template { get; set; }
public IDictionary<String, String> Params { get; set; }

表示第二类创建表名EventTypeTemplate

Column          Type
Id              string
Severity        int
Title           string
Description     string

但是我不知道如何将follow属性加入到表列名和类型

public IList<String> Categories { get; private set; }
public IList<String> Queries { get; private set; }

如有任何帮助,不胜感激

如何将类映射到数据库表

对于Template,在EventType表中,为EventTypeTemplate添加一个外键(EventTypeTemplateId):

EventType
---------
Column              Type
Id                  string
Severity            int
EventTypeTemplateId int 

Params创建一个包含三列的Params表:

Params
------
Column       Type
EventTypeId  string
Key          string
Value        string

Categories创建一个表Categories:

Categories
----------
EventTypeTemplateId string
CategoryName        string  

Queries创建一个表Queries:

Queries
----------
EventTypeTemplateId string
Query               string