2013-04-03 30 views
0

這是我的代碼,即時試圖恢復kez_customparamvalue的nvarchar字符串值。通常對於一個小數或浮點標識使用類似CrmDecimalProperty的函數hoursAsCrmNumber =小時爲CrmDecimalProperty;但我不確定在nvarchar的情況下該怎麼做。使用c#和asp.net檢索ms crm4中的單個實體的nvarchar字段

public string Retrieve_SC_Target_Rate() 
    { 

     try 
     { 

      // Create the retrieve target. 
      TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic(); 

      // Set the properties of the target. 
      targetRetrieve.EntityName = EntityName.kez_custimizationpararmeter.ToString(); 
      targetRetrieve.EntityId = new Guid ("D739150F-F68B-E211-AD2B-00155D011F06"); 

      // Create the request object. 
      RetrieveRequest retrieve = new RetrieveRequest(); 

      // Set the properties of the request object. 
      retrieve.Target = targetRetrieve; 

      // Create the column set object that indicates the properties to be retrieved. 
      ColumnSet cols = new ColumnSet(); 
      cols.Attributes = new string[] { "kez_customparamvalue" }; 
      // Set the properties of the column set. 
      retrieve.ColumnSet = cols; 

      // Indicate that the BusinessEntity should be retrieved as a DynamicEntity. 
      retrieve.ReturnDynamicEntities = true; 

      // Execute the request. 
      RetrieveResponse retrieved = (RetrieveResponse)svc.Execute(retrieve); 

      // Extract the DynamicEntity from the request. 
      DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntity; 

      Property paramValue = entity.Properties.Where(p => p.Name == "kez_customparamvalue").FirstOrDefault(); 

      if (paramValue != null) 
      {      
       // reutrn the nvarchar value of paramValue 


      } 
      return "The value is "; // + param value 

     } 
     catch (Exception e) 
     { 
      // The variable 'e' can access the exception's information. 
      return e.StackTrace.ToString(); 
     } 

    } 

回答

0

我不得不使用StringProperty返回適當的值,希望這有助於。

if (paramValue != null) 
      { 
       // reutrn the nvarchar value of paramValue 
       StringProperty stringParamValue = paramValue as StringProperty; 
       return stringParamValue.Value; 
      } 
相關問題