简体   繁体   中英

NHibernate Mapping Issue

I have the following set of tables in an existing database.

Resource - ResourceID

LocalisedResource - LocalisedResourceID, ResourceID, Language, Culture, LocalisedTerm

Office - OfficeId, NameResourceId

Now I wan to query for a particular office and get back the office's name for a particular language culture combination falling back to a default language of "EN" and culture of "GB" if no entry is found for the language and culture specified.

So, something like this...

public class Office
{
    public virtual int OfficeId { get; set; }
    public string Name { get; set; }        
}

repository.GetOffice(5 /* id */,"zh" /* language */,"cht" /* culture */);

We also want to do it for saving too...

repository.SaveOffice(office,"zh" /* language */,"cht" /* culture */);

At the moment we are doing all of our mapping in a custom written set of stored procedures using a function to pull out the correct name. This is obviously slowing us down as we have to write a lot of SPs for all our crud code.

This article on localizing NHibernate using filters might help with retrieving your object, but I don't know if it will help with saving.

Edited to add: You could map the localasied names as a collection on Office, and use a method on OFfice to lookup the localised name from the collection. Performance might be acceptable depending on how your application uses the Office object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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