c# – 缺少Models / IdentityModel.cs
我是.NET新手,目前正在学习遵循
this tutorial的ASP.NET Core MVC.
我的开发环境: > Ubuntu 16.04.1 LTS 因此,我使用yo aspnet和选定的Web应用程序创建了一个新项目,其中包括基于个人用户帐户的身份验证.在教程中,我现在处于“创建您的模型”部分,并对如何继续感到困惑. 具体来说,教程要求您创建的模型如下所示: 型号/ Model.cs: using Microsoft.EntityFrameworkCore; using System.Collections.Generic; namespace EFGetStarted.AspNetCore.NewDb.Models { public class BloggingContext : DbContext { public BloggingContext(DbContextOptions<BloggingContext> options) : base(options) { } public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; } } public class Blog { public int BlogId { get; set; } public string Url { get; set; } public List<Post> Posts { get; set; } } public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; } } } 但是,在该页面上,有一个警告:
当我找不到他们引用的文件Models / IdentityModel.cs时,我的困惑就开始了.我看到Models / ApplicationUser.cs,如下所示: using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; namespace EFGetStarted.AspNetCore.NewDb.Models { // Add profile data for application users by adding properties to the ApplicationUser class public class ApplicationUser : IdentityUser { } } …和Data / ApplicationDBContext.cs,如下所示: using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using EFGetStarted.AspNetCore.NewDb.Models; namespace EFGetStarted.AspNetCore.NewDb.Data { public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); // Customize the ASP.NET Identity model and override the defaults if needed. // For example,you can rename the ASP.NET Identity table names and more. // Add your customizations after calling base.OnModelCreating(builder); } } } 上面的警告信息使我对如何继续感到困惑.由于Models / IdentityModel.cs不存在,我是否将Model.cs的内容放入Models / ApplicationUser.cs或Data / ApplicationDBContext.cs中,还是按原样保留所有内容? 解决方法
generator-aspnet使用的是different version of templates而不是Visual C# Web Template shipped with Visual Studio 2015. 文件
您可以保持原样 – 这些文件位于何处并不重要. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |