Я пытаюсь отобразить представление моего индекса, но получаю ошибку Invalid Object Name, когда пытаюсь go перейти на свою страницу индекса. Пожалуйста, помогите мне понять, почему я получаю эту ошибку, спасибо. Дайте мне знать, если вам нужна дополнительная информация, я постарался предоставить весь соответствующий код ниже. Вот ошибка стека
SqlException: Invalid object name 'MoveAssignment'.
Microsoft.Data.SqlClient.SqlCommand+<>c.<ExecuteDbDataReaderAsync>b__164_0(Task<SqlDataReader> result)
System.Threading.Tasks.ContinuationResultTaskFromResultTask<TAntecedentResult, TResult>.InnerInvoke()
System.Threading.Tasks.Task+<>c.<.cctor>b__274_0(object obj)
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref Task currentTaskSlot, Thread threadPoolThread)
Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable<T>+AsyncEnumerator.InitializeReaderAsync(DbContext _, bool result, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync<TState, TResult>(TState state, Func<DbContext, TState, CancellationToken, Task<TResult>> operation, Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>> verifySucceeded, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable<T>+AsyncEnumerator.MoveNextAsync()
Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync<TSource>(IQueryable<TSource> source, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync<TSource>(IQueryable<TSource> source, CancellationToken cancellationToken)
PokemonSimulation.Controllers.PokedexesController.Index() in PokedexesController.cs
+
viewModel.Pokemon = await _context.Pokedex
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask<IActionResult> actionResultValueTask)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Вот метод индекса в моем контроллере
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using PokemonSimulation.Data;
using PokemonSimulation.Models;
namespace PokemonSimulation.Controllers
{
public class PokedexesController : Controller
{
private readonly PokemonSimulationContext _context;
public PokedexesController(PokemonSimulationContext context)
{
_context = context;
}
// GET: Pokedexes
//public async Task<IActionResult> Index()
//{
// var pokedex = _context.Pokedex
// .AsNoTracking();
// return View(await pokedex.ToListAsync());
//}
public async Task<IActionResult> Index()
{
var viewModel = new PokedexIndexData();
viewModel.Pokemon = await _context.Pokedex
.Include(i => i.moveAssignments)
.OrderBy(i => i.Pokemon_Name)
.ToListAsync();
return View(viewModel);
}
Вот моя модель PokedexIndexData
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PokemonSimulation.Models
{
public class PokedexIndexData
{
public IEnumerable<Pokedex> Pokemon { get; set; }
public IEnumerable<Moves> Move { get; set; }
public IEnumerable<Abilitys> Ability { get; set; }
}
}
Это мое MoveAssignment Модель
namespace PokemonSimulation.Models
{
public class MoveAssignment
{
[Key]
public int MoveID { get; set; }
public int PokedexID { get; set; }
public Moves Move { get; set; }
public Pokedex Pokedex { get; set; }
}
}
Наконец, это моя страница просмотра индекса
@model PokemonSimulation.Models.PokedexIndexData
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Name
</th>
<th>
Type1
</th>
<th>
Type2
</th>
<th>
HP
</th>
<th>
Attack
</th>
<th>
Defense
</th>
<th>
Special Attack
</th>
<th>
Special Defense
</th>
<th>
Speed
</th>
<th>
Total
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Pokemon)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Pokemon_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Type1)
</td>
<td>
@Html.DisplayFor(modelItem => item.Type2)
</td>
<td>
@Html.DisplayFor(modelItem => item.HP)
</td>
<td>
@Html.DisplayFor(modelItem => item.Attack)
</td>
<td>
@Html.DisplayFor(modelItem => item.Defense)
</td>
<td>
@Html.DisplayFor(modelItem => item.Special_Attack)
</td>
<td>
@Html.DisplayFor(modelItem => item.Special_Defense)
</td>
<td>
@Html.DisplayFor(modelItem => item.Speed)
</td>
<td>
@Html.DisplayFor(modelItem => item.Total)
</td>
<td>
<a asp-action="Index" asp-route-id="@item.PokemonId">Select</a>|
<a asp-action="Edit" asp-route-id="@item.PokemonId">Edit</a> |
<a asp-action="Details" asp-route-id="@item.PokemonId">Details</a> |
<a asp-action="Delete" asp-route-id="@item.PokemonId">Delete</a>
</td>
</tr>
}
</tbody>
</table>
{
@if (Model.Move != null)
{
<h3>Moves the Pokemon can learn</h3>
@foreach (var move in Model.Move)
{
<li>@move.Move_Name</li>
}
}
enter code here