我是.NET新手,目前學習ASP.NET Core MVC的方法如下:this tutorial。Models/IdentityModel.cs missing
我的開發環境:
- 的Ubuntu 16.04.1 LTS
- 對.NET核心1.0.0-preview2-1-003177
- Visual Studio代碼1.7.2
- 發電機ASPNET 0.2 .5(創建項目腳手架)
請隨身攜帶,因爲這是一個漫長的問題。
因此,我使用yo aspnet
創建了一個新項目,並選擇了Web Application
,其中包括基於個人用戶帳戶的驗證。在教程中,我現在處於「創建您的模型」部分,並對如何繼續操作感到困惑。
具體來說,模型教程要求您創建看起來像這樣:
型號/ 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/IdentityModel.cs時,我開始混淆了。我看到型號/ 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
{
}
}
...和數據/ 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中,還是保留原樣?
謝謝您的幫助:)