我想根据电话号码获取联系人,但在 Ms Dynamics 中,电话号码以各种格式存储,如 123 45 678、12 34 56 78、0112345678、01 12345678 等。
因此,在进行比较之前,我必须删除其中的空格,我确实尝试在字符串上使用 Replace 方法,但这在运行时给了我一个非法方法错误。
我真的必须检索所有联系人并进行另一个循环进行比较,还是有办法“清理”查询中的字符串?
string phone = "12345678";
var contacts = from c in orgContext.CreateQuery<Contact>()
join a in orgContext.CreateQuery<Account>() on c.AccountId.Id equals a.AccountId
where (c.Telephone1.Replace(" ", "").Contains(phone) || c.MobilePhone.Replace(" ","").Contains(phone))
select new DynamicContact
{
ContactId = c.ContactId,
FirstName = c.FirstName,
LastName = c.LastName,
....and more...
};
编辑:
这是异常消息:
'where' 条件无效。实体成员正在调用无效的属性或方法。