表示SQL数据库中的列表 [英] Representing a list in a SQL database

查看:121
本文介绍了表示SQL数据库中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL数据库在C#中执行应用程序。



我有一个模型:

  Person()
{
string id; // unike key
string name;
列表< string> ResponsableOf; // id
的列表

我想将其表示成一个表



表格的正确字段是什么?

解决方案

这取决于他将负责的人与他人之间的关系是什么。



如果是父和子关系,即 组合 ,您可以使用自引用表。如下所示:



人物
$ b


  • Id

  • name

  • ParentId 同一张表的外键。



如果人与其他人之间的关系是 聚合 ,并且一个人可能对许多其他 person s:



人:




  • Id

  • code> name 。



usersresponsibility




  • Id

  • PersonId

  • ResobonsiblePersonID li>


之后,在这两种情况下,在您的前端应用程序中,您将需要处理这些表中的数据,作为不是行。你应该考虑物体。



在您的应用程序中,您当前的类 Person 应映射到此表。


I'm doing an application in C# with an SQL database.

I've got a model:

Person()
{
  string id;//unike key
  string name;
  List<string> responsableOf;//list of id
}

and I want to represent it into a table.

Which are the right fields for the tables?

解决方案

It depends on what kind of relation is there between the person and the other persons that he will be responsible for.

If it is a parent and child relation i.e a composition you can use a self reference table. Something like:

Persons with the following columns:

  • Id,
  • name.
  • ParentId Foreign key to the same table.

If the relation between the person and the others is an aggregation, and a person may be responsible for many other persons:

Persons:

  • Id,
  • name.

usersresponsibilities:

  • Id,
  • PersonId,
  • ResobonsiblePersonID.

Later, in both the two cases, in your front end application you will need to deal with the data in these table as an objects not as rows. You should think in terms of objects.

In your application your current class Person should be mapped to this table.

这篇关于表示SQL数据库中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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