如何在 ORM 中使用多语言数据库模式? [英] How to use multilanguage database schema with ORM?
问题描述
美好的一天!
我正在寻找实现多语言数据库架构的最佳方法,我使用的方法与此处相同:多语言数据库设计的最佳实践是什么?(一张表包含语言中性数据,一张表用于所有翻译).它看起来很好很干净,并且不限制可能的语言数量.
I'm searching for the best way to implement multilanguage database schema, the approach I use is the same as here: What are best practices for multi-language database design? (one table with language neutral data and one for all translation). It seems to be good and clean and doesn't limit number of possible languages.
但我想使用一个简单的 ORM(如 C# 中的 LINQ、PHP 中的 Outlet 等),其中每个表都映射到实体类.这可以工作,但查询变得更加复杂.
But I want to use a simple ORM (like LINQ in C#, Outlet for PHP etc) where each table is mapped to entity class. This can work, but queries became more complex.
可能有一些特殊的技术可以将这种 DB Shema 与 ORM 一起使用?或者我可以从支持更复杂映射的更复杂的 ORM 中受益?
May be there are some special techniques to use such DB shema with ORM? Or I can benefit from more complex ORMs which support more complex mappings?
提前致谢!
推荐答案
仅使用一个表进行所有翻译可能会很快导致任何操作(选择/插入/更新/删除)的严重性能和复杂性问题;试着理解我的意思.
Using only one table for all translations may quickly lead to severe performance and complexity issues for any operation (select/insert/update/delete) ; just try it to understand what I mean.
然后我会采用以下方法(每个可翻译"对象有两个表),这似乎在性能、复杂性和维护问题之间取得了很好的平衡.
I would then go for the following method (two tables per "translatable" object), which seems a good balance between performance, complexity, and maintenance issues.
product
- id (PK)
- number1
- number2
- date1
- date2
...
product_i18n
- id (PK)
- product_id (FK)
- language_id (FK)
- string1
- string2
...
language
- id (PK)
- name
检查它是如何使用 Propel ORM (PHP) 完成的:http://propelorm.org/blog/2011/01/11/propel-gets-i18n-behavior-and-why-it-matters.html
Check how it's done with Propel ORM (PHP) : http://propelorm.org/blog/2011/01/11/propel-gets-i18n-behavior-and-why-it-matters.html
HTH
这篇关于如何在 ORM 中使用多语言数据库模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!