title: Web API controller for ViewModel
body: <p>I have designed a web application somehow similar to facebook. After login it displays data from 4 different models: <strong>Identity Model</strong> , <strong>Community Model</strong> , <strong>Forms Model</strong> and <strong>FormCommunity Model</strong> that is actually a relationship table. For this purpose I have designed a ViewModel named <strong>CommunityUserViewModel</strong>. Here is my <strong>CommunityUserViewModel</strong> code.</p>
  
  <pre><code>namespace FYP.ViewModel
  {
      public class CommunityUserViewModel
      {
          public IList&lt;Community&gt; Com  { get; set; }
          public ApplicationUser appuser { get; set; }
          public IList&lt;FormCommunity&gt; fcom { get; set; }
  
          public IList&lt;QForm&gt; qf { get; set; }
  
      }
  }
  </code></pre>
  
  <p>Now I am creating a Xamarin mobile app for this application using Web APIs. Following <a href="https://www.youtube.com/watch?v=UToBKlnig4M&amp;index=1&amp;list=PLpbcUe4chE78YvgIMtmgNEmRGyGJcsQdF" rel="nofollow noreferrer">this tutorial</a>, I have generated an authentication Token. And now at duration 20:30, I am creating a new controller of type <strong>Web API 2 Controller with actions using Entity Framework</strong> using my discussed view model as I need to play data from these multiple tables after login. On creating this new controller I am getting error as displayed in <a href="https://i.stack.imgur.com/yoaQn.png" rel="nofollow noreferrer">this image</a>. The error stated that:</p>
  
  <p><strong>There was an error running the selected code generator:
  'Unable to retrieve metadata for 'FYP.ViewModel.CommunityUserViewModel. One or more validation errors were detected during model generation.
  CommunityUserViewModel:: Entity type CommunityUserViewModel has no key defined.Define the key for this entity type.
  IdentityUserLogin:: Entity type IdentityUserLogin has no key defined.Define the key for this entity type.
  CommunityUserViewModel: Entity Type: EntitySet 
  CommunityUserViewModel that has no keys defined.</strong></p>
  
  <p>Sharing code of 2 out of 4 models that have been used in <strong>CommunityUserViewModel</strong>.</p>
  
  <p><strong>Community.cs</strong></p>
  
  <pre><code>    public class Community{
     [Key]
      public int CommunityID { get; set; }
  
      public string CommunityName { get; set; }
      public string CommunityDomain { get; set; }
      public string CommunityAbout { get; set; }
      public string CommunityLogo { get; set; }
      public int PrivacyID { get; set; }
      public string CommunityAdmin { get; set; }
  
      public virtual  ICollection&lt;CommunityUser&gt; CommunityUsers { get; set; }
      public virtual ICollection&lt;FormCommunity&gt; FormsCommunity { get; set; }   
  
      public Community(){
          FormsCommunity = new Collection&lt;FormCommunity&gt;();
          CommunityUsers = new Collection&lt;CommunityUser&gt;();
          }
  }
  </code></pre>
  
  <p><strong>ApplicationUser.cs</strong></p>
  
  <pre><code>public class ApplicationUser : IdentityUser{
  
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string UserRole { get; set; }
      public string Gender { get; set; }
  
      [DataType(DataType.Date)]
      public DateTime DOB { get; set; }
      public string ImageUrl { get; set; }
  
  }
  </code></pre>