This is a migrated thread and some comments may be shown as answers.

Startswith doesn´t work

3 Answers 77 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Petr Šatka
Top achievements
Rank 1
Petr Šatka asked on 20 Mar 2011, 10:24 PM
Hi Telerik
I am trying to write a parameterized query like this:
string s2 = "QX";
IQueryable<Ipostr> var2 = from ip in this.DataContext.Ipostrs where ip.ixs_str.StartsWith(s2) select ip;
 
List<Ipostr> ipostrs2 = var2.ToList();
...
Unfortunately it doesn´t work. It returns only one record where ip.ixs_str is equal to "QX".

The code with const string works great but it is useless for me.
const string s = "QX"; //It works
IQueryable<Ipostr> var = from ip in this.DataContext.Ipostrs where ip.ixs_str.StartsWith(s) select ip;
 
List<Ipostr> ipostrs = var.ToList();
...

In other words, the first code returns only Ipostr where ixs_str is equal to QX . The second code returns all ipostrs where ixs_str starts with QX.

What am I doing wrong?

Sorry for me english.

Regards
Peter

3 Answers, 1 is accepted

Sort by
0
Petr Šatka
Top achievements
Rank 1
answered on 21 Mar 2011, 11:32 AM
I found out where the problem is. Ixs_str is char(12). The system adds spaces at the end of the parameter. Is there a workaround? I can´t change the type of ixs_str.
0
Thomas
Telerik team
answered on 21 Mar 2011, 02:57 PM
Hi Petr,

first of all: thanks for updating your initial question, as the normal mapping with varchar/nvarchar works without a problem... but not for char/nchar; this saved ma a bit of time.
Unfortunately, this is a glitch in our LINQ that needs to be fixed; I will try to do that for the next patch. For the time beeing, you can simply add a '%' character like ip.ixs_str.StartsWith(s2+"%") as a workaround.

Thanks for reporting this issue with us!
Greetings,

Thomas
the Telerik team
0
Accepted
Thomas
Telerik team
answered on 21 Mar 2011, 03:42 PM
Hi Petr,

the issue has been fixed and the needed changes will be contained in the next patch. 

Regards,
Thomas
the Telerik team
Tags
LINQ (LINQ specific questions)
Asked by
Petr Šatka
Top achievements
Rank 1
Answers by
Petr Šatka
Top achievements
Rank 1
Thomas
Telerik team
Share this question
or