This question is locked. New answers and comments are not allowed.

Nikolai Hellwig
Top achievements
Rank 1
Nikolai Hellwig
asked on 26 May 2010, 01:04 PM
Hi,
let's assume we have 2 tables:
Table a: (ID, Address, Desc ID)
Table b: (Desc ID, Language, Text)
Is there a way to directly access the text field with the current language. Something like:
a.CurrentText
instead of
a.b.where(f => f.Language.Equals(CurrentLanguage)).Single().Text
Best Regards
Nikolai Hellwig
4 Answers, 1 is accepted
0
Hello Nikolai Hellwig,
Also you might want to consider using SingleOrDefault as it will not throw an exception if there is no such item or more than one.
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Given that it is a collection that you are accessing there is no shortcut. What you can do however is to skip the where clause. You can write it like this :
a.b.Single(f => f.Language.Equals(CurrentLanguage)).Text
Also you might want to consider using SingleOrDefault as it will not throw an exception if there is no such item or more than one.
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0

Nikolai Hellwig
Top achievements
Rank 1
answered on 27 May 2010, 06:18 PM
this is not exactly what i wanted, but thank you for your help.
what i have just done is: extending each class in a partial class with an property which links to the current language record in the text-table.
so i can access with: a.b.Text
the problem is that openaccess fires 2 sql commands. i will try using fetchgroups soon. maybe this can help.
best regards
nikolai
0

IT-Als
Top achievements
Rank 1
answered on 28 May 2010, 01:47 PM
Hi Nikolai,
I have done it in almost the same way. I have included a GetText(language) on the class to get me the text in the right language..That way you can let other (outside) logic decide what the current language is.
I have included the list of texts (in all supported languages) in the default fetch group (of the owning class)... It didn't yield any performance hit...actually it performs better because texts in all languages are fetched at once instead of searching through the list (and thus issuing a SQL statement) to find the right one to return.
Another solution I could think of is to store the texts in a Dictionary<string, string> where the first is the language code and the second is the actual text in that language... Might perform better if you're supporting many languages.
In my case I only had 3 and I guessed that it was a bit overkill to go for the Dictionary...
Regards
Henrik
I have done it in almost the same way. I have included a GetText(language) on the class to get me the text in the right language..That way you can let other (outside) logic decide what the current language is.
I have included the list of texts (in all supported languages) in the default fetch group (of the owning class)... It didn't yield any performance hit...actually it performs better because texts in all languages are fetched at once instead of searching through the list (and thus issuing a SQL statement) to find the right one to return.
Another solution I could think of is to store the texts in a Dictionary<string, string> where the first is the language code and the second is the actual text in that language... Might perform better if you're supporting many languages.
In my case I only had 3 and I guessed that it was a bit overkill to go for the Dictionary...
Regards
Henrik
0
Hello Nikolai Hellwig,
Indeed you are on the right track. Using Fetch Plans will result in Telerik OpenAccess ORM not firing 2 queries. Keep in mind that if you have a long lasting scope and you have already fetched an object, it will not be fetched again from the database.
If it is not a case when you absolutely need to be as fast as you can I would suggest not worrying about the second query.
If you need something else feel free to contact us back.
Have a great day,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Indeed you are on the right track. Using Fetch Plans will result in Telerik OpenAccess ORM not firing 2 queries. Keep in mind that if you have a long lasting scope and you have already fetched an object, it will not be fetched again from the database.
If it is not a case when you absolutely need to be as fast as you can I would suggest not worrying about the second query.
If you need something else feel free to contact us back.
Have a great day,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.