如何将类映射到数据库表?

时间:2011-04-12 00:28:46

标签: c# database database-design

我有课程,需要按照以下方式制作数据表 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>();
     } 
}

对于class 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; }

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

对于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  
相关问题