簡體   English   中英

錯誤 CS0234:命名空間“MvcMovie”中不存在類型或命名空間名稱“Data”

[英]error CS0234: The type or namespace name 'Data' does not exist in the namespace 'MvcMovie'

我目前正在嘗試自學一些 .net 核心代碼。

我目前正在關注 Microsoft 網站上的教程。

當我嘗試構建代碼時,出現以下錯誤:

/Users/xxxx/dotnet/MvcMovie/Startup.cs(1,16):錯誤 CS0234:命名空間“MvcMovie”中不存在類型或命名空間名稱“Data”(您是否缺少程序集引用?) [/Users /xxxx/dotnet/MvcMovie/MvcMovie.csproj]

我的 Startup.cs 文件看起來像這樣

using MvcMovie.Data;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace MvcMovie
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            
            services.AddDbContext<MvcMovieContext>(options =>
            options.UseSqlite(Configuration.GetConnectionString("MvcMovieContext")));
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

這是我設置命名空間(Data/MvcMovieContext.cs)的地方

using Microsoft.EntityFrameworkCore;
using MvcMovie.Models;

namespace MvcMovie.Data
{
    public class MvcMovieContext : DbContext
    {
        public MvcMovieContext (DbContextOptions<MvcMovieContext> options)
            : base(options)
        {
        }

        public DbSet<Movie> Movie { get; set; }
    }
}

我已經按照教程學習了這封信,我檢查了文件名並嘗試了谷歌。 我並不茫然。

---添加---添加了項目結構的圖像。

當前項目結構截圖1

您的Data文件夾不應放在bin/debug/net5.0下,它應與項目下的Controlles處於同一級別。

如下: 在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM