Search code examples
c#asp.net-mvcasp.net-mvc-scaffolding

Using MvcScaffold, I'm getting "Sequence contains no elements" for most files, for each model


Example error; I try to *Scaffold Controller Region -Repository* Example error; I try to Scaffold Controller Region -Repository

Region class

public class Region
{
    public int RegionId { get; set; }

    public string RegionCode { get; set; }
    public string ApiUrl { get; set; }

    public Universe[] Universes { get; set; }
}

The error repeats essentially for each file it tries to generate (the views, mostly).

I'm not sure what information to include other than this, because I have no clue what causes it. I've tried searching for a solution, but most solutions seems unrelated to my particular issue.


Solution

  • What I will suggest to you is to replace the Array by a List or better an generic interface ICollection. And then try again. Working with array you need to intialize it in the constructor.

       public class Region
      {
        public int RegionId { get; set; }
    
        public string RegionCode { get; set; }
        public string ApiUrl { get; set; }
    
        public ICollection<Universe> Universes { get; set; }
       }