views:

102

answers:

2

I am having a problem with the Dynamic Linq Library. I get a the following error "ParserException was unhandled by user code ')" or ','". I have a Dicitionary and I want to create a query based on this dictionary. So I loop through my dictionary and append to a string builder "PersonId = (GUID FROM DICTIONARY). I think the problem is were I append to PersonId for some reason I can't seem to convert my string guid to a Guid so the dynamic library don't crash.

I have tried this to convert my string guid to a guid, but no luck.

query.Append("(PersonId = Guid(" + person.Key + ")");

query.Append("(PersonId = " + person.Key + ")");

I am using VS 2010 RTM and RIA Services as well as the Entity Framework 4.

//This is the loop I use
foreach (KeyValuePair<Guid, PersonDetails> person in personsDetails)
{
    if ((person.Value as PersonDetails).IsExchangeChecked)
    {
        query.Append("(PersonId = Guid.Parse(" + person.Key + ")");
    }
}

//Domain service call
 var query = this.ObjectContext.Persons.Where(DynamicExpression.ParseLambda<Person, bool>(persons));

Please help, and if you know of a better way of doing this I am open to suggestions.

+1  A: 

Use a parameterized query, e.g.:

var query = this.ObjectContext.Persons.Where(
     "PersonId = @1", new [] { person.Key } );
Craig Stuntz
A: 

Did you try(notice the extra ')' ).

   query.Append("(PersonId = Guid(" + person.Key + "))");
Nix