190944 (1) [Avatar] Offline
#1
I'm trying to code the first example but I'm seeing an exception when I run it. Perhaps someone can give me some advice.

The db is as follows:

dbo.Books
--------------
BookId int
Title nvarchar(MAX)
Description nvarchar(MAX)
PublishedOn datetime2(7)
AuthorId int

dbo.Author
--------------
AuthorId int
Name nvarchar(MAX)
WebUrl nvarchar(MAX)

AppDbContext class is copied from the book with the Books variable defined as - public DbSet<Book> Books { get; set; }

When I run, I see the following exception: SystemData.SqlClient.SqlException 'Invalid object name 'Books'

+ $exception {System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'Books'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at MyFirstEFCoreApp.Program.ListAll() in D:\Win10_Repositories\EntityFrameworkCoreInAction\MyFirstEFCoreApp\Program.cs:line 13
at MyFirstEFCoreApp.Program.Main(String[] args) in D:\Win10_Repositories\EntityFrameworkCoreInAction\MyFirstEFCoreApp\Program.cs:line 35
ClientConnectionId:d4fb1dd9-9a37-4b1a-9dbf-9e49711fa48e
Error Number:208,State:1,Class:16} System.Data.SqlClient.SqlException