here is the language table:
create table Multilinguals(id uniqueidentifier,languageCode varchar(10),nvarchar(max) content)
so any fields want to be multilingual just set it's sq-type to uniqueidentifier refer to Multilinguals.id
here is the Role table with name field to be multilingual:
create table Roles(id uniqueidentifier,name uniqueidentifier)
and following is the classes and hbm:
namespace DomainModel
{
public class Multilingual
{
private Guid _id;
public virtual Guid Id
{
get { return _id; }
set { _id = value; }
}
private string _languageCode;
public virtual string LanguageCode
{
get { return _languageCode; }
set { _languageCode = value; }
}
private string _content;
public virtual string Content
{
get { return _content; }
set { _content = value; }
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="DomainModel" namespace="DomainModel">
<class table="Multilinguals" name="Multilingual">
<composite-id>
<key-property name="Id" column="id"></key-property>
<key-property name="LanguageCode" column="languageCode"></key-property>
</composite-id>
<property name="Content" column="content"></property>
</class>
</hibernate-mapping>
using System;
using System.Collections.Generic;
using System.Text;
using Iesi.Collections;
namespace DomainModel
{
public class Role
{
private Guid _id;
public virtual Guid Id
{
get { return _id; }
set { _id = value; }
}
private ISet _names;
public virtual ISet Names
{
get { return _names; }
set { _names = value; }
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="DomainModel" namespace="DomainModel">
<class name="Role" table="Roles">
<id name="Id" column="id">
<generator class="assigned">
</generator>
</id>
<set name="Names">
<key column="id" foreign-key="name"></key>
<one-to-many class="Multilingual"/>
</set>
</class>
</hibernate-mapping>
and following is my test:
DomainModel.Role role= session.CreateCriteria(typeof(DomainModel.Role)).List<DomainModel.Role>()[0];
Console.WriteLine(role.Names.Count);
but it always output 0
what's the problem...help.
|