title: How can l use Regex.Replace method within LINQ
body: <p>I have a controller with following method <strong>getMail()</strong>:</p>
  
  <pre><code>public JsonResult getMail(string id)
  {
      int Id = Convert.ToInt32(id);
      string pattern = @"\bmem_id\b";
      string replace = "100";         
      var result = (from a in db.tblmail_type
                    where a.Id == Id                              
                    select new MailModel
                    {
                        subject = a.Subject,
                        Content = Regex.Replace(a.Content, pattern, replace);
                    });
      return Json(result, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>This method is used for getting mail content. Before getting content, I want to replace a "mem_id" to "100" in the mail content. Default content is given below:</p>
  
  <blockquote>
    <p>Content = "You have successfully registered with Member ID: mem_id"</p>
  </blockquote>
  
  <p>I have used <code>Regex.Replace()</code> method in the LINQ. But this code doesn't change the content. When I change this code to this form which is given below, it's work properly.</p>
  
  <pre><code>public JsonResult getMail(string id)
  {
      int Id = Convert.ToInt32(id);
      var input = db.tblmail_type.Where(x=&gt;x.Id==Id).FirstOrDefault().Content;
      string pattern = @"\bmem_id\b";
      string replace = "100";            
      string content = Regex.Replace(input, pattern, replace);
      var result = (from a in db.tblmail_type
                    where a.Id == Id
                    select new MailModel
                    {
                        subject = a.Subject,
                        Content = content
                    });
      return Json(result, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>Why does this happen? Can anyone specify the reason behind this weird problem? How can I replace the "Content" within the LINQ?</p>