Getting Started with Entity Framework Core [1 of 5]

Play Getting Started with Entity Framework Core [1 of 5]

The Discussion

  • User profile image
    Sunil Anthony

    Seems like EF Core 3.0 have a problem when doing a update-database. As you can see, it is missing the slash after the username.

    CREATE FILE encountered an operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Users\sunil.anthonyContosoPet.mdf

    Thank you,
    Sunil Anthony

  • User profile image
    Sunil Anthony

    Nevermind, I did some digging around and find out it was SQL 2017 MSSQL Local DB that had a bug and needed to be updated.

  • User profile image
    Jonathan Wood

    So, I see this was posted just last month. Yet, there are numerous changes between this video and the latest version of Visual Studio. For one thing, when I create a Razor Pages project, Entity Framework is already added to my project. (And NuGet has no Microsoft.EntityFrameworkCore.Design.) Also, when you created the data classes, it seemed like using statements for the data annotations namespaces were already added where I had to add them. There were a number of other differences too. And it would've been nice if you mentioned how to configure so that I can specify nullable strings and the like.

    .NET has been so fluid lately. Every time I come to build a new website, it seems like everything has changed again. So is anyone going to post a video like this for this month?

    Also, I started using computers around MS-DOS v1. There were no icons and commands had to be typed in. When Microsoft started adding the moniker "Visual" to everything it was to emphasize the point and click nature of those systems. So I find it interesting that progress now means I have to type commands into the console to build my database. I wonder if the current Visual Studio developers even know where the name Visual Studio moniker came from or what it meant.

  • User profile image

    And BTW, my personal take is that the EDMX file was waaaaay easier than all the hoops that need to be jumped through when using the new and "improved" version of .NET and EF.

  • User profile image
    @Sunil Anthony:

    This is a well-known problem. They are not fixing it because the bug is in SQL Server 2017.

    I overcame it easily by first creating the database. Look for the connection string (appsettings.json) and the database server is something like (localdb)\MSSQLLOCALDB. Go to SSMS or Object Explorer and connect to this server. Then create a brand new database with the same name in the connection string. You can take the opportunity to reduce the length of the name from its cryptic guid version.
  • User profile image
    Received the following error:

    Inconsistent accessibility: Property type order is less than "ProductOrder.Order". Has anyone received a similar error when going through the sample?
  • User profile image
    Is this guy trolling or what?
    Followed the steps & copied from his screen apart from the OnConfiguring override which I left out bc I have no connection string to use.

    Tried running Add-Migration and get rejected bc no database provider has been configured.

    Try to include the OnConfiguring override only to realize the database with connection string doesnt exist.

    Added a database as a .mdf and have no idea what im doing but got a connection string for it.

    Used this connection string to create the OnConfiguring override and was able to use the Add-Migration command.

    Now I have this weird .mdf file and no idea what to do next so I'm just rocking back and forth on the floor, cutting myself in the dark.
    Nice video though
  • User profile image

    Zero useful information.

  • User profile image
    if the connectiosString must not be there. Why you don't place it where it belong?

    because of this people never learn the right way
  • User profile image

    He actually doesn't say that - he says "... You should probably never hardcode your connection string".

    If he were to do it in a more "Right" way - the he would need to add a configuration file, the supporting configuration infrastructure to load the configuration data (which admitedly isn't a lot) but it is still more complicated than a string.

    But... that assumes that confguration files are the Right way. This is a console app - maybe it should be passed in as a parameter. So he should be grabbing the connection string from the arguments?

    Or maybe it could be used as part of a Docker solution so maybe it should be read from the environment variables.

    How should we store our connection strings?
  • User profile image

    at offset=8:25 Cam says "add a nullable email" but proceeds to code it to be non-null (since is within the "#nullable enable" block. However the immediately following migration magically fixes it as nullable:true, so there is obviously some sleight of hand (off-camera) fix. Viewer beware !

  • User profile image

    at offset=11:50 Cam writes "if (squeakyBone is Product)" condition. This is WRONG because the variable is instance of type Product (even if null), so the test should have been "if (squeakyBone != null)"

  • User profile image
    To anyone with problems with that initial migration, create an additional constructor with no parameters for your DbContext implementation (because of no DI service config).

    Refer to this doc page, section "Using a constructor with no parameters":

    Also, just in case you also have problems with that, run '> SqlLocalDB.exe create "Test" -s' to create a local db.
  • User profile image

    The value "null" is not an instance of Product.

    There are lots of ways:

    "if (scndProd != default)"

    "if (obj is Product)"

    "if (obj is null)"


Add Your 2 Cents