我正在尝试搜索联系人,例如存储在name字段中的值"Café“,但是当我像”咖啡馆“一样搜索时不会返回任何记录。
我试着做了以下工作
using (ServiceContext svcContext = new ServiceContext(_serviceProxy))
     {
       var query_where3 = from c in svcContext.ContactSet
                         join a in svcContext.AccountSet
                         on c.ContactId equals a.PrimaryContactId.Id
                         where c.FullName.Normalize(NormalizationForm.FormD).Contains("Café")
                         select new
                         {
                          account_name = a.Name,
                          contact_name = c.LastName
                         };
}并显示异常,其消息为“无效'where‘条件。
发布于 2015-01-23 19:05:55
一切都是关于
.Normalize(NormalizationForm.FormD),可能EF不知道如何处理此方法。移除它,然后用
c.FullName.Contains("Café")在2015年增加-01-30
所以,伙计,我能想到的唯一的解决方案是在你做where条件之前列出。这样,一旦linq 2对象处理了这个问题,您就可以使用正常化。尝试:
(from c in svcContext.ContactSet join a in svcContext.AccountSet
on c.ContactId equals a.PrimaryContactId.Id 
select new {a=a,c=c}    ).ToList()
.Where(c=>c.FullName.Normalize(NormalizationForm.FormD).Contains("Café"))
.Select( x=> select new  {
                          account_name = x.a.Name,
                          contact_name = x.c.LastName
                         };)但是,如果linq 2在应用程序服务器内存中运行,而不是在数据库服务器中运行,则会造成一定的开销。
发布于 2015-01-26 18:38:05
不能在LinQ上使用该函数,正确的查询方法是:
c.FullName == "someString" or c.FullName.equals("someString").这是因为您不能在左边的条件上使用函数或转换。您必须使用属性本身。
您的查询如下:
using (ServiceContext svcContext = new ServiceContext(_serviceProxy))
     {
       var query_where3 = from c in svcContext.ContactSet
                         join a in svcContext.AccountSet
                         on c.ContactId equals a.PrimaryContactId.Id
                         where c.FullName == "Café" || c.FullName == "Cafe"
                         select new
                         {
                          account_name = a.Name,
                          contact_name = c.LastName
                         };
}发布于 2015-01-27 06:52:06
一般情况下,您无法处理Linq到SQL的重音。而且,对于Linq到CRM所能做的事情,您甚至受到更多的限制。您不能修改DB;除非您不关心被支持。然后你可以做一些类似的事情: MAD建议和一个数据库更改。
ALTER TABLE Name ALTER COLUMN Name [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AI
我个人不建议这样做。
我能想到的最好的方法是尽可能接近数据,并从列表或类似的列表中过滤数据。我必须一直这样做,这是一个痛苦(并增加更多的开销),但没有真正的解决办法,我已经找到了。
    //declare a dictionary 
    Dictionary<string, string> someDictionary = new Dictionary<string, string> ();
    using (ServiceContext svcContext = new ServiceContext(_serviceProxy))
     {
       var query_where3 = from c in svcContext.ContactSet
                         join a in svcContext.AccountSet
                         on c.ContactId equals a.PrimaryContactId.Id
                         where  c.FullName.Contains("Caf")
                         select new
                         {
                          account_name = a.Name,
                          contact_name = c.LastName
                         };
}
//then
    foreach(var q in query_where3)
    {
        if(string.IsNullOrEmpty(account_name)==false && string.IsNullOrEmpty(contact_name)==false)
    {
        someDictionary.Add(account_name, contact_name);
    }
    }//then you can add the .Normalize(NormalizationForm.FormD) to your dictionary
希望能帮上忙。
https://stackoverflow.com/questions/28116867
复制相似问题