开发者

Linq - get compare with transliterated value of fields

I have a table (sql server). One of its columns ('Name') Contains Cyrillic values.

From parameters i recieve value, that contains in this fields but the are transliterated.

i mean something like: 'Вася' -> 'Vasya'. And i need to translite开发者_StackOverflowrate value field first;

var q = from r in m_DataContext.Table where CTransliteration.Transliterate(r.Name).Contains(trans_text) select r;

or

m_DataContext.Table.Select(r => r.name=CTransliteration.Transliterate(r.Name))


I've never seen "CTransliteration.Transliterate" - am I right in assuming that this comes from your own software/a 3rd party library?

The Linq query that you are targeting at the DataContext is transformed into SQL, and then executed on SQL Server. You wouldn't have a way to express the query that you want to run in SQL: CTransliteration.Transliterate is not part of the SQL language.

I think there are two ways you can go: a) Split the query into a part that runs on SQL Server, and do the transliteration in .NET. For the SELECT you've listed that's not a problem:

m_DataContext.Table
 .ToList()
 .Select(r => r.name=CTransliteration.Transliterate(r.Name));

For the WHERE clause, this makes a poor choice as you'd need to transfer everything to the application server and then do the filtering.

b) Move the transliteration functionality into a CLR function in SQL Server, and run the query via SQL, not Linq.


You might find more luck with string.Compare(r.Name, "Your Value", CultureInfo.xxx, CompareOptions.xxx) ?


I resolved with 2 linq queries.

  1. i created a new small class

    public class SmallClass { public int Id { get; set; } public String Name { get; set; } }

And after i implemented next logic:

...

var q = from r in GetAllTable() select new SmallClass{ Id = r.ID, Name = CTransliteration.Transliterae(r.Name)) };


var rr = from r in q where r.Name.Contains(trans_text) select r;

i't' working...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜