title: Using .NET Core MVC response displays NULL value of one of property
body: <p>Using .Net Core 3.1 MVC pattern, I have been developing a back-end system. There are two tables, one is &quot;TranslationInfo&quot;, another one is &quot;TranslationContent&quot;. TranslationInfo has many TranslationContent, so I configured the Dbcontext like this.</p>
  <p><strong>TranslationInfo</strong></p>
  <pre><code>    public class TranslationInfo
      {
          [Key]
          public int Index { get; set; }
          public DateTime InsertedDate { get; set; }
          public DateTime UpdatedDate { get; set; }
      }
  </code></pre>
  <p><strong>TranslationContent</strong></p>
  <pre><code>   public class TranslationContent
      {
          [Key]
          public int Code { get; set; }
          public string English { get; set; }
          public string French { get; set; }
          public string Status { get; set; }
          public string Message { get; set; }
  
          [ForeignKey(&quot;Index&quot;)]
          public TranslationInfo TranslationInfo { get; set; }
      }
  </code></pre>
  <p>Everything is alright except for getting a list of TranslationContent based on TranslationInfo.Index or not. The result displays the list of TranslationContent w/o TranslationInfo even though it enables to retrieve the result based on TranslationInfo.Index.</p>
  <p><strong>Result of 'https://localhost:44311/contentsList/3'</strong></p>
  <pre><code>[
      {
          &quot;code&quot;: 1,
          &quot;english&quot;: &quot;string&quot;,
          &quot;french&quot;: &quot;string&quot;,
          &quot;status&quot;: &quot;&quot;,
          &quot;message&quot;: &quot;&quot;,
          &quot;translationInfo&quot;: null
      },
      {
          &quot;code&quot;: 2,
          &quot;english&quot;: &quot;string&quot;,
          &quot;french&quot;: &quot;string&quot;,
          &quot;status&quot;: &quot;string&quot;,
          &quot;message&quot;: &quot;string&quot;,
          &quot;translationInfo&quot;: null
      },
      {
          &quot;code&quot;: 4,
          &quot;english&quot;: &quot;cvzxvc&quot;,
          &quot;french&quot;: &quot;asdfasdfas&quot;,
          &quot;status&quot;: &quot;Passed&quot;,
          &quot;message&quot;: null,
          &quot;translationInfo&quot;: null
      },
      {
          &quot;code&quot;: 10,
          &quot;english&quot;: &quot;string&quot;,
          &quot;french&quot;: &quot;string&quot;,
          &quot;status&quot;: &quot;string&quot;,
          &quot;message&quot;: &quot;string&quot;,
          &quot;translationInfo&quot;: null
      }
  ]
  </code></pre>
  <p>Here is <strong>Application</strong> area.</p>
  <p><strong>ITranslationService.cs</strong></p>
  <pre><code>  public interface ITranslationServices
      {
          List&lt;TranslationInfo&gt; GetTranslationInfos();
  
          TranslationInfo GetTranslationInfo(int index);
          TranslationInfo CreateTranslationInfo(TranslationInfo translationInfo);
  
          TranslationInfo EditTranslationInfo(TranslationInfo translationInfo);
          List&lt;TranslationContent&gt; GetTranslationContents();
          List&lt;TranslationContent&gt; GetTranslationContentsByIndex(int index);
  
          TranslationContent GetTranslationContent(int code);
          TranslationContent CreateTranslationContent(TranslationContent translationContent);
  
          TranslationContent EditTranslationContent(TranslationContent translationContent);
      }
  </code></pre>
  <p><strong>TranslationService.cs</strong></p>
  <pre><code>using Excel.DB;
  using Microsoft.AspNetCore.Http;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Excel.Core
  {
      public class TranslationService : ITranslationServices
      {
          private readonly AppDbContext _context;
  
          public TranslationService(AppDbContext context)
          {
              _context = context;
          }
  
  
  
          /*     Translation Info Area */
          public List&lt;TranslationInfo&gt; GetTranslationInfos()
          {
              return _context.TranslationInfos.ToList();
          }
          public TranslationInfo GetTranslationInfo(int index)
          {
              return _context.TranslationInfos.First(t =&gt; t.Index == index);
          }
  
          public TranslationInfo CreateTranslationInfo(TranslationInfo translationInfo)
          {
              translationInfo.InsertedDate = DateTime.UtcNow;
              translationInfo.UpdatedDate = DateTime.UtcNow;
  
              _context.Add(translationInfo);
              _context.SaveChanges();
              return translationInfo;
          }
  
          public TranslationInfo EditTranslationInfo(TranslationInfo translationInfo)
          {
              var dbTranslationInfo = _context.TranslationInfos.First(t =&gt; t.Index == translationInfo.Index);
              // update process will be added.
  
              dbTranslationInfo.UpdatedDate = DateTime.UtcNow;
              _context.SaveChanges();
              return dbTranslationInfo;
  
          }
  
  
          /*     Translation Content Area */
          public List&lt;TranslationContent&gt; GetTranslationContents()
          {
              return _context.TranslationContents.ToList();
          }
          public List&lt;TranslationContent&gt; GetTranslationContentsByIndex(int index)
          {
              return _context.TranslationContents.Where(t =&gt; t.TranslationInfo.Index == index).ToList();
          }
  
          public TranslationContent GetTranslationContent(int code)
          {
              return (TranslationContent)_context.TranslationContents.First(t =&gt; t.Code == code);
          }
  
          public TranslationContent CreateTranslationContent(TranslationContent translationContent)
          {
              var dbTranslationInfo = _context.TranslationInfos.First(t =&gt; t.Index == translationContent.TranslationInfo.Index);
  
              if (dbTranslationInfo == null)
              {
                  throw new Exception(&quot;Cannot find translation info&quot;);
              }
  
              translationContent.TranslationInfo = dbTranslationInfo;
  
              _context.Add(translationContent);
              _context.SaveChanges();
              return (TranslationContent)translationContent;
          }
  
          public TranslationContent EditTranslationContent(TranslationContent translationContent)
          {
              var dbTranslationContent = _context.TranslationContents.First(t =&gt; t.Code == translationContent.Code);
              // update process will be added.
  
              dbTranslationContent.English = translationContent.English;
              dbTranslationContent.French = translationContent.French;
              dbTranslationContent.Message = translationContent.Message;
              dbTranslationContent.Status = translationContent.Status;
              dbTranslationContent.TranslationInfo = translationContent.TranslationInfo;
              _context.SaveChanges();
              return dbTranslationContent;
          }
      }
  }
  
  </code></pre>
  <p>Here is API(Controller) area
  <strong>TranslationController</strong></p>
  <pre><code>using Microsoft.AspNetCore.Mvc;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Excel.Core;
  using Excel.DB;
  
  namespace Excel.API.Controllers
  {
      [ApiController]
      [Route(&quot;[controller]&quot;)]
      public class TranslationController : ControllerBase
      {
          private readonly ITranslationServices _translationServices;
  
          public TranslationController(ITranslationServices translationServices)
          {
              _translationServices = translationServices;
          }
  
          [HttpGet(&quot;/infos&quot;)]
          public IActionResult GetTranslationInfos()
          {
              return Ok(_translationServices.GetTranslationInfos());
          }
  
          [HttpGet(&quot;/info/{index}&quot;, Name = &quot;GetTranslationInfo&quot;)]
          public IActionResult GetTranslationInfo(int index)
          {
              return Ok(_translationServices.GetTranslationInfo(index));
          }
  
          [HttpPost(&quot;/info&quot;)]
          public IActionResult CreateTranslationInfo(TranslationInfo translationInfo)
          {
              var newTranslationInfo = _translationServices.CreateTranslationInfo(translationInfo);
              return CreatedAtRoute(&quot;GetTranslationInfo&quot;, new { newTranslationInfo.Index }, newTranslationInfo);
          }
  
          [HttpPut(&quot;/info&quot;)]
          public IActionResult EditTranslationInfo(TranslationInfo translationInfo)
          {
              return Ok(_translationServices.EditTranslationInfo(translationInfo));
          }
  
          [HttpGet(&quot;/contents&quot;,Name = &quot;GetTranslationContents&quot;)]
          public IActionResult GetTranslationContents()
          {
              return Ok(_translationServices.GetTranslationContents());
          }
  
          [HttpGet(&quot;/contentsList/{index}&quot;, Name = &quot;GetTranslationContentsByIndex&quot;)]
          public IActionResult GetTranslationContentsByIndex(int index)
          {
              return Ok(_translationServices.GetTranslationContentsByIndex(index));
          }
  
          [HttpGet(&quot;/content/{code}&quot;, Name = &quot;GetTranslationContent&quot;)]
          public IActionResult GetTranslationContent(int code)
          {
              return Ok(_translationServices.GetTranslationContent(code));
          }
  
          [HttpPost(&quot;/content&quot;)]
          public IActionResult CreateTranslationContent(TranslationContent translationContent)
          {
              var newTranslationContent = _translationServices.CreateTranslationContent(translationContent);
              return CreatedAtRoute(&quot;GetTranslationContent&quot;, new { newTranslationContent.Code }, newTranslationContent);
          }
  
          [HttpPut(&quot;/content&quot;)]
          public IActionResult EditTranslationContent(TranslationContent translationContent)
          {
              return Ok(_translationServices.EditTranslationContent(translationContent));
          }
      }
  }
  
  </code></pre>
  <p>Can you let me know how I can get the TranslationInfo when getting the list of TranslationContent?</p>