markjprice / cs11dotnet7

Repository for the Packt Publishing book titled "C# 11 and .NET 7 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
563 stars 207 forks source link

Chapter 12: Creating a class library for entity models using SQLite' help needed. #70

Open Jammerref2015 opened 1 year ago

Jammerref2015 commented 1 year ago

In chapter 12. I am trying to follow the 'Creating a class library for entity models using SQLite'. I follow the 10 steps but I am not getting any Classes generated. I have NorthwindContext.cs created. Am I doing something wrong? Missing a step? I have the DB connected, I can see the data in SQLite/SQLserver Compact Toolbox.

markjprice commented 1 year ago

Mostly likely the dotnet-ef tool cannot find the database file in the location specified. If the database file is missing, then the SQLite database provider will create an empty database file and since it is empty, you get a DbContext class generated but not any entity model classes.

If you are doing Chapter 12, then you would have had to run the dotnet-ef tool in Chapter 10 on page 453 as well. Did you get it to work then? What are you doing differently this time? Are you in the correct folder when you enter the command? Does the command use the correct relative path to the database file?

Jammerref2015 commented 1 year ago

Yup That was it. Sorted now. Thanks. :-)

Jammerref2015 commented 1 year ago

I am getting red lines now. For Index and Name in each of the class files..

Switching from [Index("CategoryName", Name = "CategoryName")] to [Microsoft.EntityFrameworkCore.Index("LastName", Name = "LastName")] removes them. Is this ok?

markjprice commented 1 year ago

Yes, that's fine, but you shouldn't need to specify the fullname namespace before the class name for the Index attribute. It's namespace should have been imported like line 5 here: https://github.com/markjprice/cs11dotnet7/blob/main/vs4win/PracticalApps/Northwind.Common.EntityModels.Sqlite/Category.cs#L5