none
Entity collection filter issue RRS feed

  • Question

  • Hi,

    I have an entity collection on which i need to filter at some point of time. MyEnitity collection binded with single quote ('), when i try to apply filter on that entity column it throws me error as 'Not a valid join operator'

    String sUsername="Conn's";

    Example: Entitycollection.Select("UserName='"+sUsername+"'");

    Please suggess how to resolve this issue.

    -Ramesh

    Thanks,

    Ramesh

    • Moved by Paul Zhou Monday, October 17, 2011 9:00 AM move for better support (From:Regular Expressions)
    Saturday, October 15, 2011 7:34 AM

All replies

  • It's probably better to use LINQ to query the EntityCollection. Linq automatically takes care of the required escaping of parameters. 

    var things = from thing in anEntityCollection where Username = sUsername select thing;
    


    Otherwise you will have to ensure your special characters are properly escaped, ' needs to be doubled up to '' and there are other special characters you will need to take care of.

    As the proper solution to this problem lies in the way you query the data, not in how you filter out the special characters, I recommend you direct further questions to the ADO.NET, Linq2Sql and EntityFramework forums.

     

     

    Saturday, October 15, 2011 10:24 AM
  • You can also use a lambda expression:

    var things = anEntityCollection.Where(thing => string.Equals(thing.Username, sUsername));

    Saturday, October 15, 2011 10:26 AM
  • Hi RameshT,

    I think you can refer this link about the difference between "Select" and "Where": http://social.msdn.microsoft.com/Forums/nl-BE/adodotnetdataproviders/thread/b09c3955-934a-4fd1-be66-a0739e7538ae

    @ Jesse is right for your question, please feel free let us know your feedback.

    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.

    Wednesday, October 19, 2011 9:20 AM
    Moderator
  • Hi,

    Thanks for your reply.

    Public class EntityCollection<Entity> : ObjectCollection<Entity>, ISerializable where Entity:BusinessObjectBase

    My entity collection base class is as mentioned above. I have only entitycollection.Select() i don't find entitycollection.Where() in it.

    Please advise.

    Thanks,

    Ramesh

    Thursday, October 20, 2011 10:50 AM
  • ObjectCollection is winform collection, the LINQ query is on IQueryable and IEnumerable. I think you should modify your base class.


    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.

    Friday, October 21, 2011 8:13 AM
    Moderator