动态 Linq 库 Guid 异常
我在使用动态 Linq 库时遇到问题。我收到以下错误“ParserException 未由用户代码 ')”或 ','" 处理。我有一个字典,我想基于此字典创建一个查询。所以我循环遍历我的字典并附加到字符串生成器“PersonId =(字典中的 GUID)。我认为问题是,如果我出于某种原因附加到 PersonId,我似乎无法将字符串 guid 转换为 Guid,这样动态库就不会崩溃。
我尝试过将字符串 guid 转换为 guid,但没有成功。
query.Append("(PersonId = Guid(" + person.Key + ")");
query.Append("(PersonId = " + person.Key + ")");
我正在使用 VS 2010 RTM 和 RIA 服务以及实体框架 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));
请提供帮助,如果您知道更好的方法,我愿意接受建议。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于与动态 linq 的 GUID 比较,请使用查询属性和 Equals() 方法,如提供的示例中所示。
For GUID comparison with dynamic linq use query properties and the Equals() method like in the provided sample.
使用参数化查询,例如:
Use a parameterized query, e.g.:
你尝试过吗(注意额外的')')。
Did you try(notice the extra ')' ).