SqlException: Invalid object name 'Mems'.

0

witam,dodałem nowy model Mems

public class Mems
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        public string Autor { get; set; }
        [Required]
        public string Title { get; set; }
        public string coverImg { get; set; }
        [Required]
        public string Description { get; set; }
        public string Category { get; set; }
        [Required]
        public DateTime? releaseDate { get; set; }
        public DateTime? modifyDate { get; set; }
        public int? Like { get; set; }
        public int? Dislike { get; set; }
    }

kiedy wywołuje się Views ->Home->index

@using Microsoft.AspNetCore.Identity
@using MemeGenerator.Models
@model IEnumerable<MemeGenerator.Models.Mems>
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
@{
    ViewData["Title"] = "Home Page";
}
@if (SignInManager.IsSignedIn(User))
{
    <p>Jesteś zalogowany</p>
}
else
{
    <p>Nie jesteś zalogowany</p>
}
h1>@ViewData["Title"]</h1>
@Html.ActionLink("+ Dodaj mema", "Create", "Movie", null, new { @class = "btn btn-primary", @style = "margin-bottom: 20px;" })
<br>
<table class="table">
    <tr>
        <th>Id</th>
        <th>Tytul</th>
        <th>coverImage</th>
        <th>Descriptionอ</th>
        
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td class="item-id">@item.Id</td>
            <td>@item.Title</td>
            <td>
                <img src="@item.coverImg" height="80px" />
            </td>
            <td>@item.releaseDate.Value.ToString("dd MMM yyyy")</td>
            <td>@item.Category</td>
            <td>@item.modifyDate</td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { id = item.Id, @class = "btn btn-primary", @style = "margin-bottom: 20px;" })
            </td>
            <td>
                <input type="button" value="Delete" class="btn btn-danger" />
            </td>
        </tr>
    }
</table>
@using (Html.BeginForm("delete", "movie", FormMethod.Post, new { name = "frmMovie", id = "frmMovie" }))
{
    <input type="hidden" name="id" />
}

@section Scripts
    {
    <script>
        $(".btn-danger").click(function () {
            if(!confirm('Do you really want to delete this movie?')) {
                return false;
            }
            var id = $(this).closest("tr").find(".item-id").text();
            document.frmMovie.id.value = id;
            document.getElementById("frmMovie").submit();
        });
    </script>
}


wywala mi taki błąd
An unhandled exception occurred while processing the request.
SqlException: Invalid object name 'Mems'.
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, bool breakConnection, Action<Action> wrapCloseInAction)

AspNetCore.Views_Home_Index.ExecuteAsync() in Index.cshtml
+
@foreach (var item in Model)

robiłem drop-database,add-migration i update-database ale nie pomaga ,ktos wie co źle robię?

0

Sprawdź czy ConnectionString wskazuje na odpowiednią bazę. Sprawdź czy baza zawiera tabele o nazwie Mems

0

ConnectionString wskazuje na odpowiednią bazę
https://imgur.com/UTNJnin -brakuje Mems chyba ,ja kto mozna naprawic?

0

Korzystasz z EF? Według mnie masz złą nazwę klasy. Nie "Mems" tylko "Mem" a EF sam zrobi liczbe mnogą. Druga sprawa czemu masz atrybut required na kolumnie i jednocześnie może ona przyjmować null? Dodaj Mems do DBContextu jako DBSet

0

w modelu memyContext mam DbSet Mem

public partial class memyContext : DbContext
    {
        public memyContext()
        {
        }

        public memyContext(DbContextOptions<memyContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Mem> Mem { get; set; }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

           
            modelBuilder.Entity<Mem>(entity =>
            {
                entity.HasKey(e => e.Id);

                entity.Property(e => e.Id)
                    .HasColumnName("Id_mema")
                    .ValueGeneratedNever();

                entity.Property(e => e.Autor)
                    .HasColumnName("autor")
                    .HasColumnType("text");

                entity.Property(e => e.Dislike).HasColumnName("dislike");

                entity.Property(e => e.Like).HasColumnName("like");
                entity.Property(e => e.Description).HasColumnName("opis")
                .HasColumnType("text");
                entity.Property(e => e.Category)
                    .HasColumnName("kategoria")
                    .HasColumnType("text");
                entity.Property(e => e.Category)
                    .HasColumnName("img")
                    .HasColumnType("text");
                entity.Property(e => e.modifyDate)
                    .HasColumnName("modyfikacja")
                    .HasColumnType("date");
                entity.Property(e => e.releaseDate)
                    .HasColumnName("relase")
                    .HasColumnType("date");
            });
        }


        
    }

teraz mam dbo.Mem
https://imgur.com/K0gHXhN
zamieniłem na Mem ale nadal to samo

1 użytkowników online, w tym zalogowanych: 0, gości: 1