1

My model looks like this:

namespace Flow.Models
{    
    public abstract class Project
    {
        public int ID { get; set; }

        public String HashID { get; set; }

        public string FileLoc { get; set; } //Use HashedID above.
        public bool Network { get; set; }

        public int ClientID { get; set; }
        public int FirmID { get; set; }

        public ICollection<Order> Orders { get; set; }
    }
}

AND

namespace Flow.Models
{
    public class ProjectDepo : Project
    {    
        public DateTime DepoDate { get; set; }  //some way to set this to only the date
        public TimeSpan DepoTime { get; set; } //some way to set this to only the time of day

        public bool DepoNoticeReceived { get; set; } //yes or no

        //public int FirmUserID { get; set; }
    }
}

When I scaffold ProjectDepo, I receive these types of error messages:

CS1061 'CreateModel' does not contain a definition for 'DepoNoticeReceived' and no extension method 'DepoNoticeReceived' accepting a first argument of type 'CreateModel' could be found (are you missing a using directive or an assembly reference?)

AND

CS1061 'CreateModel' does not contain a definition for 'Network' and no extension method 'Network' accepting a first argument of type 'CreateModel' could be found (are you missing a using directive or an assembly reference?)

Only for the fields that I have set a 'public bool'.

In the database, both 'Network' and 'DepoNoticeReceived' are set as 'bit'. One is nullable and the other is not.

I do not know why the Scaffolding generates these errors.

Please pass along any ideas.

thank you for any assistance.

chuck

Collin Barrett
  • 2,441
  • 5
  • 32
  • 53
user1489765
  • 291
  • 2
  • 12
  • It seems it's a duplicated question. Take a look in this other question [here](https://stackoverflow.com/questions/50788533/cannot-scaffold-ef-core-2-1-model-that-contains-a-bool-item) – Renato Aloi Jun 11 '18 at 17:31
  • If you could point me to the duplicate question I would greatly appreciate it. When I try the link, it points back to this question. thank you, chuck – user1489765 Jun 11 '18 at 22:19
  • Sorry, my bad. The copy&paste betrayed me. Here is the correct link: https://stackoverflow.com/questions/46349821/asp-net-core-and-scaffold?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Renato Aloi Jun 11 '18 at 23:07
  • Reading the other post inidcated this is a bug in the Scaffolding. For some reason, bool values are NOT being properly referenced by scaffolding. Probably should be a bug for future releases of EF/Core. Much thanks to @RenatoAloi for taking the time to guide me to the (duplicate question) answer. – user1489765 Jun 12 '18 at 14:25

1 Answers1

3

Reading the other post indicated this is a bug in the Scaffolding. For some reason, bool values are NOT being properly referenced by scaffolding. Probably should be a bug for future releases of EF/Core. (This is still in EF/Core 2.1)

@Html.DisplayNameFor(model => model.Network)

(The above is the scaffolded code, which fails.)

@Html.DisplayNameFor(model => model.ProjectDepo.Network)

This is the correct code. It fills in the missing model 'ProjectDepo'.

(This find is due to the guidance of @Renato Alio. thank you for the guidance.)

chuck

user1489765
  • 291
  • 2
  • 12