简体   繁体   English

图形和关系数据库

[英]Graph and relational database

I'm looking for the best way to store and query a family tree (a graph of people with their relationships like a genealogy ) into a relational database. 我正在寻找最好的方法来存储和查询一个家谱(一个人与他们的关系,如家谱的图表)到关系数据库。

I guess, that can be easily achieved by using a graph database but I have a strong constrain. 我想,通过使用图形数据库可以轻松实现这一点,但我有很强的约束力。

I use .NET and Microsoft technologies, and the ideal is probably to find some kind of technology that can sit on top of a relational DB so that both can be used at the same time .. 我使用.NET和Microsoft技术,理想的可能是找到一种可以放在关系数据库之上的技术,这样两者都可以同时使用。

Any suggestions or advices are welcome ! 欢迎任何建议或建议!

Thanks guys Riana 谢谢你们Riana

Since any given person can have only one mother and one father (not necessarily both known), you don't need a generalized representation of directed graph. 由于任何给定的人只能拥有一个母亲和一个父亲(不一定都是已知的),因此您不需要有向图的广义表示。 A simple "binary" graph like this should be sufficient: 像这样的简单“二进制”图应该就足够了:

在此输入图像描述

Querying for siblings, ancestors, descendants etc... should be fairly simple in this model. 在这个模型中,查询兄弟姐妹,祖先,后代等等应该相当简单。

I think there is a Graph database that is targeted towards .Net. 我认为有一个针对.Net的Graph数据库。 It is called BrightStarDB Sparql and LinQ as a means to query. 它被称为BrightStarDB Sparql和LinQ作为查询的手段。

gramps (http://gramps-project.org/) is an opensource (http://www.gramps-project.org/wiki/index.php?title=Portal:Developers) genealogy platform. gramps(http://gramps-project.org/)是一个开源(http://www.gramps-project.org/wiki/index.php?title=Portal:Developers)族谱平台。 It's written in python and had downloads for working on windows. 它是用python编写的,有下载工作在windows上。 Depending on your motivations (eg why you need it to be a relational db) it may work for you out of the box, or you may want to use it just to examine it's source code. 根据你的动机(例如为什么你需要它成为一个关系数据库)它可能对你开箱即用,或者你可能只是想用它来检查它的源代码。 It has a data abstraction layer so can work with several underlying db's (http://www.gramps-project.org/wiki/index.php?title=Using_database_API). 它有一个数据抽象层,因此可以使用几个底层数据库(http://www.gramps-project.org/wiki/index.php?title=Using_database_API)。 So you can get access to whichever db you use independently from gramps. 因此,您可以访问您从gramps独立使用的任何数据库。 For example you could use gramps to load all your data to 'make' your database but then use that independently for your queries. 例如,您可以使用gramps来加载所有数据以“制作”您的数据库,然后单独使用它来进行查询。

If you have a table 如果你有一张桌子

FamilyTree
----------
ID       int not null PK,
ParentID int,
Name     nvarchar(50)

You can query relationships with simple joins. 您可以使用简单连接查询关系。

This is how to get all siblings to a person with ID=@SearchPersonID 这是如何让所有兄弟姐妹到ID=@SearchPersonID

select sibling.* from FamilyTree parent
inner join FamilyTree child
on parent.ID = child.ParentID
inner join FamilyTree sibling
on parent.ID = sibling.ParentID
where child.ID <> sibling.ID
where child.ID = @SearchPersonID

To get cousins you need two levels of joins etc. 为了获得表兄弟,你需要两个级别的连接等。

To get a whole familytree things gets a little bit more complicated, but you can use a recursive CTE to generate all decendants from a given parent. 要获得一个完整的familytree,事情变得有点复杂,但是您可以使用递归CTE来生成给定父级的所有后代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM