This project is read-only.

Localized data, howto?

Oct 14, 2010 at 12:04 PM

Hello,

I want to create a database for a multilingual environment. My thought was to have basetables which contain non-text data, and for each table a localized table that contains the text fields.

Example:

PRODUCTS table:
productid (PK, database identity)
number
price
category

LOCALIZEDPRODUCTS table:
productid (PK)
languageid (PK)
name
description

I wanted the make the products table the parent of the localizedproducts table, so I could get all the data directly from the localizedproducts. Unfortunately it is not possible to assign the products table as parent, because the primary keys are not the same.

Is there another way to match these tables in nHydrate, or should I link the tables in code myself? Suggestions for another solution to my question are also welcome.

Regards,

Eric van den Bos

Oct 14, 2010 at 5:45 PM

Base tables must have the same key as children. However why not just make ProductID the PK? Language is just another attribute of the object. Simply remove it from the key. Or you can make the two table joined on ProductID and walk to the object. For example you can use the following syntax to get the local product.

var product = ProductCollection.RunSelect(x=>x.ProductID == 1).FirstOrDefault();
var localProduct = product.LocalizedProductList.FirstOrDefault(x=>x.LanguageId == 2);

Oct 15, 2010 at 8:40 AM

Thanks for your reaction, codetools.

I do not understand your first solution. The PK has to be unique, but I need to have 2 or more records in the LocalizedProducts table with the same ProductID, so I can't match the tables on that field. For the same reason it is not possible to add a new ID field as PK, for that would result in duplicate records in de Products table.

Your second proposal would work, but results in two separate objects when accessing the DTO's: one containing the base information (Products) and the other containing the localized descriptions (LocalizedProducts). I would, preferably, deal with just one object.
Of course it is possible to create my own object which contains data from both tables, but isn't nHydrate supposed to arrange this for me?