Startswith doesn´t work

4 posts, 1 answers
  1. Petr Šatka
    Petr Šatka avatar
    21 posts
    Member since:
    Mar 2011

    Posted 20 Mar 2011 Link to this post

    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
  2. Petr Šatka
    Petr Šatka avatar
    21 posts
    Member since:
    Mar 2011

    Posted 21 Mar 2011 Link to this post

    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.
  3. DevCraft banner
  4. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 21 Mar 2011 Link to this post

    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
  5. Answer
    Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 21 Mar 2011 Link to this post

    Hi Petr,

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

    Regards,
    Thomas
    the Telerik team
Back to Top