2014-01-28 33 views
0

我下面LINQ到实体查询URL编码查询

var spSiteUrl = ConfigurationManager.AppSettings["SharePointURL"]; 
var spDocRoot = string.Format(Resources.Global.SharePointDocumentPathRoot, DateTime.Now.Year); 


var Docs = (from s in _espEntities.SignupDocuments 
      join r in _espEntities.RegistrationRequirements 
       on s.DocumentTypeId equals r.Id 
      where s.TaxEntityPlatformId == thisTaxEntity.TaxEntityPlatformId 
      select new NewBpnRegistrationRequestTypeSubmittedDocument() 
      { 

       DocumentType = r.Description, 

       DocumentUrl = spSiteUrl + "/Documents/" + spDocRoot + "/" + 
        thisTaxEntity.TaxEntityPlatformId + "/" + "Registration/" +    
        s.SharepointDocumentName 

      }).ToArray(); 
    if (Docs.Count() != 0) 
    { 
     newBpn.SubmittedDocuments = Docs; 

    } 

我想要做的就是使用HttpUtility.UrlEncode方法上documenturl获得通过。

请协助

回答

0

由于LINQ到实体不支持此(因为该方法不能转换为SQL),而LINQ to Objects做,你可以尝试将数据加载到anonymous ojbects,然后一起工作LINQ to Objects

var Docs = (from s in _espEntities.SignupDocuments 
      join r in _espEntities.RegistrationRequirements 
      on s.DocumentTypeId equals r.Id 
      where s.TaxEntityPlatformId == thisTaxEntity.TaxEntityPlatformId 
      select new 
      { 
       DocumentType = r.Description, 
       DocumentUrl = spSiteUrl 
        + "/Documents/" 
        + spDocRoot + "/" 
        + thisTaxEntity.TaxEntityPlatformId 
        + "/Registration/" 
        + s.SharepointDocumentName 
      }) 
      .ToArray() // Load data and continue with linq-to-object 
      .Select (n => new NewBpnRegistrationRequestTypeSubmittedDocument 
       { 
       DocumentType = n.DocumentType, 
       DocumentUrl = HttpUtility.UrlEncode (n.DocumentUrl) 
       }) 
      .ToArray(); 
+0

,它可以像预期的那样快速地工作。 – user989865

-1
 select new 
        { 

         DocumentType = r.Description, 

         DocumentUrl = spSiteUrl + "/Documents/" + spDocRoot + "/" + 
          thisTaxEntity.TaxEntityPlatformId + "/" + "Registration/" +    
          s.SharepointDocumentName 

        }).ToArray().Select(p=>new  
       NewBpnRegistrationRequestTypeSubmittedDocument{ 
        DocumentType =p.DocumentType, 
        DocumentUrl =HttpUtility.UrlEncode(p.DocumentUrl) 
       }); 
+0

这将失败,因为URL编码不是一个sql方法 – Maess

0

你不能做到这一点,同时呼吁的背景下,因为SQL没有对URL编码功能,所以你需要做一些事情,如以下:

添加以下属性NewBpnRegistrationRequestTypeSubmittedDocument

TaxEntityPlatformId 
SharepointDocumentName 

然后:

select new NewBpnRegistrationRequestTypeSubmittedDocument() 
     { 

      DocumentType = r.Description, 

      SharepointDocumentName= SharepointDocumentName, 
      TaxEntityPlatformId = TaxEntityPlatformId 

     }).ToArray(); 

然后通过阵列迭代,设置DocumentUrl如下

doc.DocumentUrl = HttpUtility.UrlEncode(spSiteUrl + "/Documents/" + spDocRoot + "/" + 
        doc.TaxEntityPlatformId + "/" + "Registration/" +    
        doc.SharepointDocumentName); 
+0

谢谢Maess的回答。唯一的挑战是增加一个额外的,因为这是一个WCF服务公开的类。 – user989865