views:

640

answers:

1

I'm trying to get nHibernate to join the name of the structure that is stored in separate table into the structure POCO object.

The database looks something like this:

+-----------+  +------------+  +-----------+
| Structure |  | Texts      |  | Languages |
+===========+  +============+  +===========+
| Id        |  | Id         |  | Id        |
| NameId    |  | LanguageId |  | Name      |
| FieldA    |  +------------+  +-----------+
| FieldB    |
+-----------+

I would like the POCO object to look like the following:

public class Structure
{
 public Structure()
 {
 }

 public long Id
 {
  get { return name; }
  set { name = value; }
 }

 public string Name
 {
  get { return name; }
  set { name = value; }
 }

 public string FieldA
 {
  get { return name; }
  set { name = value; }
 }

 public string FieldB
 {
  get { return name; }
  set { name = value; }
 }

 private long id;
 private string name;
 private string fieldA;
 private string fieldB;
}

So what I am trying to achive is to get the name property of the POCO object joined in from the Texts table with the following criteria:

Texts.Id=Structure.NameId AND Texts.Id=CurrentLanguageId

(CurrentLanguageId would be stored in the application and mapped into nHibernate)

So how to map this join in nHibernate and how to inject a property from the application into the join.

+1  A: 

If you're looking to localize your NHibernate queries, take a look at this.

Mauricio Scheffer
Thanks that worked perfectly.
Joakim Karlsson