title: Cannot implicitly convert type 'int?' to 'System.Collections.Generic.List<Model>
body: <p>I am new to MVC and LINQ.</p>
  
  <p>I am trying to provide a model to a view using LINQ.
  This model is comprised of a list of another model.</p>
  
  <p>This is the first model.    </p>
  
  <pre><code>public class MasterCategoryModel
  {
      [Key]
      public int CategoryId { get; set; }
  
      [Required(ErrorMessage = "Category name is mandatory")]
      [StringLength(255, ErrorMessage = "Category name cannot exceed 255 characters")]
      [Display(Name = "Category name ")]
      public string Name {get;set;}
  
      [StringLength(1000, ErrorMessage = "Category description cannot exceed 1000 characters")]
      [Display(Name = "Category description")]
      public string Description{get;set;}
  }
  </code></pre>
  
  <p>This is the more problematic model:</p>
  
  <pre><code>public class CategoryModel
  {
      [Key]
      public int CategoryId { get; set; }
  
      [Required]
      [StringLength(255, ErrorMessage = "Category name cannot exceed 255 characters")]
      [Display(Name = "Category nam")]
      public string Name { get; set; }
  
      [StringLength(1000, ErrorMessage = "Category description cannot exceed 1000 characters")]
      [Display(Name = "Category description")]
      public string Description { get; set; }
  
      [Required]
      public List&lt;MasterCategoryModel&gt; MasterCategory { get; set; }
  }
  </code></pre>
  
  <p>In my controller I currently have the following:</p>
  
  <pre><code>[Authorize(Users = "Administrator")]
  [HttpGet]
  public PartialViewResult _SubCategory()
  {
      using (var db = new TSCEntities())
      {
          var query = from p in db.Categories
                      where p.ParentCategoryId != null
                      select new CategoryModel() 
                      { 
                         CategoryId = p.CategoryId, 
                         Name = p.Name, 
                         Description = p.Description, 
                         MasterCategory = p.ParentCategoryId 
                      };
  
          return PartialView(query.ToList());
      }
  }
  </code></pre>
  
  <p><code>MasterCategory = p.ParentCategoryId</code> fails.</p>
  
  <p>Can anyone help with a LINQ expression which would somehow give a List?</p>
  
  <p>Database table code:</p>
  
  <pre><code>CREATE TABLE [product].[Categories](
      [CategoryId] [int] IDENTITY(1,1) NOT NULL,
      [Name] [nvarchar](255) NOT NULL,
      [Description] [nvarchar](1000) NULL,
      [ParentCategoryId] [int] NULL,
  PRIMARY KEY CLUSTERED 
  (
      [CategoryId] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  
  GO
  
  ALTER TABLE [product].[Categories]  WITH CHECK ADD  CONSTRAINT [FK_Category_ParentCategory] FOREIGN KEY([ParentCategoryId])
  REFERENCES [product].[Categories] ([CategoryId])
  GO
  
  ALTER TABLE [product].[Categories] CHECK CONSTRAINT [FK_Category_ParentCategory]
  GO
  </code></pre>
  
  <p>This is the class generated by EF.</p>
  
  <pre><code>public partial class Category
      {
          public Category()
          {
              this.Categories1 = new HashSet&lt;Category&gt;();
          }
  
          public int CategoryId { get; set; }
          public string Name { get; set; }
          public string Description { get; set; }
          public Nullable&lt;int&gt; ParentCategoryId { get; set; }
  
          public virtual ICollection&lt;Category&gt; Categories1 { get; set; }
          public virtual Category Category1 { get; set; }
  
  
      }
  </code></pre>