title: ToString Method Overriding in DataContract in WCF
body: <p>Even though i have overriden ToString method in the DataContract by returning ActivityType.Code property value in for class ActivityType. I'm still not geting the  ActivityType.Code property value on a client for binding the grid.can one let me know how the ToString method be available to Client.</p>
  
  <p>Here is the code base</p>
  
  <p>Data Contract</p>
  
  <pre><code>  [DataContract]
      public class Activity
      {
          [DataMember]
          public ActivityType ActivityTypeId { get; set; }
          [DataMember]
          public string Code { get; set; }
          [DataMember]
          public string Description { get; set; }
          [DataMember]
          public EntityStatus Status { get; set; }
  
      }
      [DataContract]
      public enum EntityStatus
      {
          [EnumMember]
          Active = 0,
          [EnumMember]
          Inactive = 1
      }
  
      [DataContract]
      public class ActivityType
      {
          [DataMember]
          public string Code { get; set; }
          [DataMember]
          public string Name { get; set; }
          [DataMember]
          public string Description { get; set; }
  
          public override string ToString()
          {
              if (Code != null)
              {
                  return Code.ToString(CultureInfo.InvariantCulture);
              }
              else
              {
                  return base.ToString();
              }
          }
      }
  </code></pre>
  
  <p>Service Implementation</p>
  
  <pre><code>  public class TimeSheetManagementService : ITimeSheetManagementService
      {
          public List&lt;BusinessEntities.Activity&gt; GetActivities()
          {
              TimeSheetManagementDataController controller = new TimeSheetManagementDataController();
  
  
              var activities = controller.GetActivities();
              var activitiesresult = activities.Select(activity =&gt; new BusinessEntities.Activity()
                                                                       {
                                                                           ActivityTypeId =
                                                                               new BusinessEntities.ActivityType()
                                                                                   {
                                                                                       Code = activity.ActivityType.Code,
                                                                                       Description =
                                                                                           activity.ActivityType.
                                                                                           Description,
                                                                                       Name = activity.ActivityType.Name
                                                                                   },
                                                                           Code = activity.Code,
                                                                           Description = activity.Description,
                                                                           Status =  (EntityStatus)  Enum.Parse(typeof(EntityStatus),Convert.ToString((activity.Status==true)?1:0))
                                                                       });
  
              return activitiesresult.ToList();
          }
      }
  </code></pre>
  
  <p>Client Implementation</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"&gt;
              &lt;Columns&gt;
               &lt;asp:BoundField runat="server" DataField="Code"/&gt;
  
               &lt;asp:BoundField runat="server" DataField="Description"/&gt;
  
               &lt;asp:BoundField runat="server" DataField="Status"/&gt;
  
               &lt;asp:BoundField runat="server" DataField="ActivityTypeId"/&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>  Code Description                   Status    ActivityTypeId
      ACT2    Requirement Feasibility Study Inactive TimeSheetManagementServiceRef.ActivityType
      ACT1    Requirement analysis    Inactive     TimeSheetManagementServiceRef.ActivityType
  </code></pre>