Nhibernate and property localization

103 مرّات مشاهدة
التخطي إلى أول رسالة غير مقروءة

Marc Climent

غير مقروءة،
04‏/03‏/2010، 6:49:37 ص4‏/3‏/2010
إلى nhusers
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">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).

cliff vaughn

غير مقروءة،
04‏/03‏/2010، 7:02:00 ص4‏/3‏/2010
إلى nhu...@googlegroups.com
have you tried just using the "order", or "orderby" property in your mapping for the list?


--
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.




--
thanks

cliff

Marc Climent

غير مقروءة،
04‏/03‏/2010، 9:02:49 ص4‏/3‏/2010
إلى nhusers
The thing is not the ordering, but how to associate the field with
it's translation using Nhibernate.

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>

Fabio Maulo

غير مقروءة،
04‏/03‏/2010، 9:03:41 ص4‏/3‏/2010
إلى nhu...@googlegroups.com
one more
http://www.codewrecks.com/blog/index.php?p=41

I love the world of options!!!

2010/3/4 Marc Climent <m.cl...@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.




--
Fabio Maulo

Fabio Maulo

غير مقروءة،
04‏/03‏/2010، 9:07:58 ص4‏/3‏/2010
إلى nhu...@googlegroups.com
<map> of <component> instead of <element> ?

2010/3/4 Marc Climent <m.cl...@adapting.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.




--
Fabio Maulo

Fabio Maulo

غير مقروءة،
04‏/03‏/2010، 9:08:19 ص4‏/3‏/2010
إلى nhu...@googlegroups.com
<map> of <component> instead of <element> ?

2010/3/4 Marc Climent <m.cl...@adapting.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.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Marc Climent

غير مقروءة،
04‏/03‏/2010، 10:43:32 ص4‏/3‏/2010
إلى nhusers
Thanks Fabio, I already read that article and it's a very interesting
approach and effectively uses <map> of <component> but maps by entity
id as the key column and works well if you have only one localizable
field but I can't see how to map several fields. For example (not real
code):

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

Fabio Maulo

غير مقروءة،
04‏/03‏/2010، 11:05:09 ص4‏/3‏/2010
إلى nhu...@googlegroups.com
I'm not concentrated in this issue but something smell as <dynamic-component> 

2010/3/4 Marc Climent <m.cl...@adapting.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.




--
Fabio Maulo

Dinoboy

غير مقروءة،
04‏/03‏/2010، 10:00:21 ص4‏/3‏/2010
إلى nhusers
I'm using this approach described here
http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/
. I don't use components nor elements, all related objects are
entities.
When I need to show data in the listview, I create specific query in
HQL which returns projections which are optimized for the needs of the
view.

Marc Climent

غير مقروءة،
10‏/03‏/2010، 8:06:10 ص10‏/3‏/2010
إلى nhusers
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. I
asked there if anyone knows how to do that.

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...

Fabio Maulo

غير مقروءة،
10‏/03‏/2010، 8:35:11 ص10‏/3‏/2010
إلى nhu...@googlegroups.com
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.cl...@adapting.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.




--
Fabio Maulo

Marc Climent

غير مقروءة،
10‏/03‏/2010، 8:39:09 ص10‏/3‏/2010
إلى nhusers
Neither. But doing it with NH is the first step to do it with FNH.

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

Fabio Maulo

غير مقروءة،
10‏/03‏/2010، 8:46:59 ص10‏/3‏/2010
إلى nhu...@googlegroups.com
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.cl...@adapting.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.




--
Fabio Maulo

Marc Climent

غير مقروءة،
10‏/03‏/2010، 9:45:41 ص10‏/3‏/2010
إلى nhusers
Thanks for your interest, Fabio. You're right.

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.
>
> > > --

Fabio Maulo

غير مقروءة،
10‏/03‏/2010، 6:15:47 م10‏/3‏/2010
إلى nhu...@googlegroups.com
There are various interpretations of your question and the answer can be from a no-mapped-relation(solved in client side), update=false insert=false, formula and so on

2010/3/10 Marc Climent <m.cl...@adapting.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.




--
Fabio Maulo

Nexus

غير مقروءة،
11‏/03‏/2010، 6:10:16 ص11‏/3‏/2010
إلى nhusers
As a side note , or even a question that popped up to talking with a
dba on this :

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

Marc Climent

غير مقروءة،
11‏/03‏/2010، 6:50:09 ص11‏/3‏/2010
إلى nhusers
You're right Nexus. We've been debating if the complexity of the
solutions is good from the DB standpoint and in brief the response
was: no.

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.

Dinoboy

غير مقروءة،
11‏/03‏/2010، 3:24:18 ص11‏/3‏/2010
إلى nhusers
I actually don't quite understand the problem you are having.

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?

Marc Climent

غير مقروءة،
11‏/03‏/2010، 7:47:26 ص11‏/3‏/2010
إلى nhusers
Yes, the question was if there's another option, as in FNH is not
possible to specify the column of a many-to-one relationship (uses
always PK).

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 Maulo

غير مقروءة،
11‏/03‏/2010، 8:26:41 ص11‏/3‏/2010
إلى nhu...@googlegroups.com
2010/3/11 Marc Climent <m.cl...@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

Marc Climent

غير مقروءة،
11‏/03‏/2010، 12:53:01 م11‏/3‏/2010
إلى nhusers
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 Maulo

غير مقروءة،
11‏/03‏/2010، 2:02:46 م11‏/3‏/2010
إلى nhu...@googlegroups.com
Can you post about the whole experience ?
Would you like to cross-post in NH-Forge ?

2010/3/11 Marc Climent <m.cl...@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.




--
Fabio Maulo

Marc Climent

غير مقروءة،
16‏/03‏/2010، 8:21:15 ص16‏/3‏/2010
إلى nhusers
Been there, done that:

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>

Fabio Maulo

غير مقروءة،
16‏/03‏/2010، 8:26:29 ص16‏/3‏/2010
إلى nhu...@googlegroups.com
near to MIRACLE!!
Going to twett it

2010/3/16 Marc Climent <m.cl...@adapting.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.




--
Fabio Maulo

Fabio Maulo

غير مقروءة،
16‏/03‏/2010، 8:33:50 ص16‏/3‏/2010
إلى nhu...@googlegroups.com
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:



2010/3/16 Marc Climent <m.cl...@adapting.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.




--
Fabio Maulo

Marc Climent

غير مقروءة،
16‏/03‏/2010، 11:28:26 ص16‏/3‏/2010
إلى nhusers
Yes, and it's very easy, I updated the wiki.

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>

الرد على الكل
رد على الكاتب
إعادة توجيه
0 رسالة جديدة