Right now I have a kind of localizable field which is is stored like
in <a href="http://fabiomaulo.blogspot.com/2009/06/localized-property-
with-nhibernate.html">this article</a>, using a UserType that
serializes itself to a database field. This solution has worked for
months but now a list must be sorted by a field of this type and the
table contains a lot of rows, so sorting by this field forces us to
retrieve all the entities on the table to get the value of the
localizable string and sort them. That's pretty inefficient.
Another complexity is that an entity can have several of this
localizable properties so my idea was to create a couple of tables,
one containing the reference to the entity and the field and the other
containing the values for each particular language:
Dictionary |dict_id|entity_id|entity_field_name|
DictionaryValues |dict_id|locale_id|value|
This table structure can be mostly achieved as explained in <a
href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-
domain-model-with-nhibernate-and-c/">this other article</a>, but now I
need to establish the link with the entity id and the entity field and
I don't know how to do it using NHibernate in an elegant way (i.e.
getting automatically the field name and looking for the right
entity_field_name in the Dictionary table and not having to specify
the current culture id but getting it from the current Thread).
So, the thing becomes quite challenging for me right now and I'm sure
that some solution can be found with some help.
Any idea? (I promise a post on my blog whenever I find a good
solution).
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
On 4 mar, 13:02, cliff vaughn <cliftonfvau...@gmail.com> wrote:
> have you tried just using the "order", or "orderby" property in your mapping
> for the list?
>
>
>
> On Thu, Mar 4, 2010 at 5:49 AM, Marc Climent <m.clim...@adapting.com> wrote:
> > I have found some articles about this particular subject but they do
> > not solve what I want to achieve and I ran out of ideas.
>
> > Right now I have a kind of localizable field which is is stored like
> > in <a href="http://fabiomaulo.blogspot.com/2009/06/localized-property-
> > with-nhibernate.html<http://fabiomaulo.blogspot.com/2009/06/localized-property-with-nhiber...>">this
> > article</a>, using a UserType that
> > serializes itself to a database field. This solution has worked for
> > months but now a list must be sorted by a field of this type and the
> > table contains a lot of rows, so sorting by this field forces us to
> > retrieve all the entities on the table to get the value of the
> > localizable string and sort them. That's pretty inefficient.
>
> > Another complexity is that an entity can have several of this
> > localizable properties so my idea was to create a couple of tables,
> > one containing the reference to the entity and the field and the other
> > containing the values for each particular language:
>
> > Dictionary |dict_id|entity_id|entity_field_name|
> > DictionaryValues |dict_id|locale_id|value|
>
> > This table structure can be mostly achieved as explained in <a
> > href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-
> > domain-model-with-nhibernate-and-c/<http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-...>">this
> > other article</a>, but now I
> > need to establish the link with the entity id and the entity field and
> > I don't know how to do it using NHibernate in an elegant way (i.e.
> > getting automatically the field name and looking for the right
> > entity_field_name in the Dictionary table and not having to specify
> > the current culture id but getting it from the current Thread).
>
> > So, the thing becomes quite challenging for me right now and I'm sure
> > that some solution can be found with some help.
>
> > Any idea? (I promise a post on my blog whenever I find a good
> > solution).
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
The thing is not the ordering, but how to associate the field with
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
class Document {
public virtual Guid Id { get; set; }
public virtual string Code { get; set; }
public virtual LocalizableString Title { get; set; }
public virtual LocalizableString Description { get; set; }
}
I should find the localized string in the strings table through the
Document.Id as well as the field name, a string column value like
"document_name" or "document_title" in order to find the right
translation. I there any way to do that using NHibernate?
On 4 mar, 15:07, Fabio Maulo <fabioma...@gmail.com> wrote:
> <map> of <component> instead of <element> ?
>
> 2010/3/4 Marc Climent <m.clim...@adapting.com>
> > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Buns...@googlegroups.com>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/nhusers?hl=en.
>
> > > --
> > > thanks
>
> > > cliff
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> Fabio Maulo
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
Anyway, I've been looking at the solution and I'm quite frustrated,
feeling like a noob...
I've been able to do the trick if there's only one Localizable
property per entity but I don't know how to tell NHibernate that I
want to create several relationships from one entity to the other
using different columns.
On 4 Març, 16:00, Dinoboy <dark...@gmail.com> wrote:
> I'm using this approach described herehttp://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibern...
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
On 10 Març, 14:35, Fabio Maulo <fabioma...@gmail.com> wrote:
> I don't understand where your problem is...
> You can't do it with NHibernate or you can't do it with FNH ?
>
> 2010/3/10 Marc Climent <m.clim...@adapting.com>
> > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Buns...@googlegroups.com>
>
> > > > > > .
> > > > > > For more options, visit this group at
> > > > > >http://groups.google.com/group/nhusers?hl=en.
>
> > > > > --
> > > > > thanks
>
> > > > > cliff
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> Fabio Maulo
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
I couldn't reproduce Dinoboy's solution in FNH, but if it's the only
solution I will try harder.
The question is: is specifying the "column" property of a <many-to-
one> relationship the way to tell NH that I don't want to use the
default id to create a relationship?
Maybe I'm making it too complicated.
On 10 Març, 14:46, Fabio Maulo <fabioma...@gmail.com> wrote:
> if so what mean this:
> "Nice solution, but using Fluent NHibernate I can't set the columns of the
> entity table that I want to map to the localizations table."
>
> 2010/3/10 Marc Climent <m.clim...@adapting.com>
> > > > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Buns...@googlegroups.com>
> > <nhusers%252Buns...@googlegroups.com<nhusers%25252Bun...@googlegroups.com>
>
> > > > > > > > .
> > > > > > > > For more options, visit this group at
> > > > > > > >http://groups.google.com/group/nhusers?hl=en.
>
> > > > > > > --
> > > > > > > thanks
>
> > > > > > > cliff
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "nhusers" group.
> > > > To post to this group, send email to nhu...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>
> > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Buns...@googlegroups.com>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/nhusers?hl=en.
>
> > > --
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
I understand these sort of patterns if you want to dump your resource
files in a database, but the underlying question is it really that
important and frequent that an application should be able to add an
additional language to his object translations ? If the answer is
yes(more like a resource file style) then you probably should use a
solution like this, but if the answer is no, because for example in a
erp application, you have domain languages (allowed languages) for
instance only french, dutch is allowed, it is not so likely and easy
to add an additional language, because all your objects should be
translated, and the cost on the db side to make joins , the flunky
cache on these solutions(which are nice) isn't really worth it. Just
add name_nl,name_fr to scheme, it can be indexed, sorted, queried in a
db friendly way, in your application it can be projected according to
users language (for instance :)).
Kind regards
So, for the cases where a localization dictionary is needed (some
particular cases, where sorting by that column is important and there
may be a lot of entities) we'll make a NH <map> to store all the
translations. On the common cases where the translation is not so
important, we'll keep using our current solution using a IUserType
that serializes all the translations to a nvarchar(max) column
(moreless like Fabio's article on uNhAddins LocalizablePropertyType
http://fabiomaulo.blogspot.com/2009/06/localized-property-with-nhibernate.html).
Anyway, thanks to the people that contributed to this topic.
@Fabio I tried that solution and as well specifying manually the
columns in the mapping (not using FNH). Seems to work, but at the end
we decided that exposed above, the solution using IUserType is valid
on 99% of the cases and we'll use a map for some critical cases.
You said:
"The question is: is specifying the "column" property of a <many-to-
one> relationship the way to tell NH that I don't want to use the
default id to create a relationship?"
Answers is yes.
For example, mapping localizable names properties in NH looks like
this:
<many-to-one name="FirstName" column="firstname_id"
class="Translation" fetch="join" />
<many-to-one name="LastName" column="lastname_id" class="Translation"
fetch="join" />
FNH equivalent should be:
References(person => person.FirstName,
"firstname_id").FetchType.Join();
References(person => person.LastName, "lastname_id").FetchType.Join();
Is this what you meant?
Actually the solution you linked works but at the end we decided not
to go all the way and just localize some particular cases using a
translation table for each entity that needs a localizable property
that has to be sorted via SQL.
@Fabio I tried that solution and as well specifying manually the
columns in the mapping (not using FNH). Seems to work, but at the end
we decided that exposed above, the solution using IUserType is valid
on 99% of the cases and we'll use a map for some critical cases.
Fortunately this time the KISS principle won the fight.
On 11 Març, 14:26, Fabio Maulo <fabioma...@gmail.com> wrote:
> 2010/3/11 Marc Climent <m.clim...@adapting.com>
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
http://nhforge.org/wikis/howtonh/localization-techniques.aspx
Thanks.
On 11 Març, 20:02, Fabio Maulo <fabioma...@gmail.com> wrote:
> Can you post about the whole experience ?
> Would you like to cross-post in NH-Forge ?
>
> 2010/3/11 Marc Climent <m.clim...@adapting.com>
>
>
>
> > That's what you get when you turn off the screen, relax and think. ;-)
>
> > Fortunately this time the KISS principle won the fight.
>
> > On 11 Març, 14:26, Fabio Maulo <fabioma...@gmail.com> wrote:
> > > 2010/3/11 Marc Climent <m.clim...@adapting.com>
>
> > > > @Fabio I tried that solution and as well specifying manually the
> > > > columns in the mapping (not using FNH). Seems to work, but at the end
> > > > we decided that exposed above, the solution using IUserType is valid
> > > > on 99% of the cases and we'll use a map for some critical cases.
>
> > > URRA!!!
> > > At the end a guy has understood that the matter is not "XYZ vs ABC" but:
> > > when XYZ is the low cost solution I'll use XYZ
> > > where XYZ is not enough I'll use ABC
> > > and where XYZ and ABC are too much I'll use resource-files
>
> > > --
> > > Fabio Maulo
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
On 16 Març, 13:33, Fabio Maulo <fabioma...@gmail.com> wrote:
> Marc, only a note...
> With LocalizablePropertyType you can expose a simple string in your domain.
> The LocalizablePropertyType can be mapped to a property or to a field and
> you can expose a property of type string.
> The example is in this post:http://fabiomaulo.blogspot.com/2009/06/localized-property-with-nhiber...
>
> 2010/3/16 Marc Climent <m.clim...@adapting.com>
> > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Buns...@googlegroups.com>