After creating a new Razor web forms app I scaffolded in an existing database:

Scaffold-DbContext "Server=<server>;Database=<db-name>;User ID=<username>;Password=<password>;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

And kept getting an error on the newly created entries:

A namespace cannot directly contain members such as fields 

After ensuring I had added Entity Framework to the project using NuGet, I still got the error.

So it turns out I was using a namespace like this:

using System;
using System.Collections.Generic;

namespace web-app3.Models
    public partial class TblStories

But this isn’t allowed – no hyphens. I had to rename my project to webapp3 and it was all fine.

Last modified: May 7, 2019



Write a Reply or Comment

Your email address will not be published.