如何将类映射到数据库表? [英] How to map class to database table?

查看:265
本文介绍了如何将类映射到数据库表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  public class EventType 
{
public String Id {get;私人集}
public int严重性{get;组; }
public EventTypeTemplate Template {get;组; }
public IDictionary< String,String> Params {get;组; }
public EventType(string id)
{
Id = id;
Params = new Dictionary< string,string>();
}
}

第二类

  public class EventTypeTemplate 
{
public String Id {get;私人集}
public int严重性{get;组; }
public String标题{get;组; }
public String描述{get;组; }
public IList< String>分类{get;私人集}
public IList< String>查询{get;私人集}
public EventTypeTemplate(string id)
{
Id = id; Categories = new List< string>();
Queries = new List< string>();
}
}

对于类1 b $ b作为表名称EventType

 列类型
Id字符串
严重性int

我不知道如何输入这些属性到表列名和类型

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

第二类
我创建表名EventTypeTemplate



列类型
标识字符串
严重性int
标题字符串
描述字符串

但我不知道如何在表列名和类型中输入跟随属性

  public IList< String>分类{get;私人集} 
public IList< String>查询{get;私人集}

任何帮助都会感激。

解决方案

对于模板,在 EventType 表中, EventTypeTemplate EventTypeTemplateId ):

  EventType 
---------
列类型
Id字符串
严重性int
EventTypeTemplateId int

对于 Params 创建一个 Params 列:

  Params 
------
列类型
EventTypeId string
键字符串
值字符串

code>创建一个名为的表

  b $ b ---------- 
EventTypeTemplateId string
CategoryName string


$ b b

查询创建名为的查询

 查询
----------
EventTypeTemplateId string
查询字符串


I'm have classes and need to make data tables as follow Class 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>();
        }
   }

And second class

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>();
     } 
}

For class 1(EventType) I create the table As table name EventType

Column    type
Id        string
Severity  int

And I don’t know how to enterprate these property into table column name and type

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

for second class I create table name EventTypeTemplate

Column          Type
Id              string
Severity        int
Title           string
Description     string

But I don’t know how to enterprate follow property into table column name and type

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

any help will be appreciated

解决方案

For Template, in the EventType table, add a foreign key to the EventTypeTemplate (EventTypeTemplateId):

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

For Params create a Params table with three columns:

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

For Categories create a table called Categories:

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

For Queries create a table called Queries:

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

这篇关于如何将类映射到数据库表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆