How to sort localized data in EntityFramework query? RRS feed

  • Question

  • Hi All,

    We have to implement localization in our application  and we're using EF 4.1, code first approach in our development. We would be storing the content in same column in multiple language and a separate language identifier column will identify the language of data. We're not sure how we can sort the localized content using EF's LINQ queries.  I don't see any option to pass "COLLATE" to SQL server from EF. Any help would be highly appreciated.




    Monday, December 5, 2011 4:55 PM

All replies

  • Hi Gurmit,


    According to your description, You want to sort the column with different language. I think it doesn't seem relate to EF.

    using (var db= new EFTestContext())
                    var test = db.Employees.OrderBy(e=>e.Name).ToList();

    Actually, it will be translate to "T-SQL" and excute in database, so it based on how to sort in database.

    [Extent1].[EmployeeId] AS [EmployeeId], 
    [Extent1].[Name] AS [Name], 
    [Extent1].[Phone] AS [Phone], 
    [Extent1].[Email] AS [Email], 
    [Extent1].[ModifyTime] AS [ModifyTime]
    FROM [dbo].[Employees] AS [Extent1]
    ORDER BY [Extent1].[Name] ASC

    But I'm not familiar with the mechanism in DB, thanks for understanding.

    BTW, here is a language packs for EF4.1:

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 6, 2011 8:55 AM
  • Hi Alan
    Thanks for your answer. I believe it is related to EF. Let me explain it again please. Assume there is "Products" table with following structure and data-
    ID (Primary Key)          Name (nvarchar(200))     Description(nvarchar(200))      LanguageID(FK)
    1                                           TV                                To Watch Program                    1
    2                                           टी वी (In Hindi)              कार्यक्रम देखने के लिए                        2
    Now I want to retreive all the products in "Hindi" language (for language Id 2) and want to sort them on "Name" field (or any other localised field). How can I achieve that using EF LINQ queries? I can't just use "OrderBy" to "sort" localized data.
    Tuesday, December 6, 2011 10:53 AM