2016-12-06 67 views
3

我是.NET新手,目前學習ASP.NET Core MVC的方法如下:this tutorialModels/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中,還是保留原樣?

謝謝您的幫助:)

回答

-1

的警告是,當你比用於認證的方法無認證選擇其他的。

如果您選擇個人用戶帳戶,將爲使用數據庫創建一個新的Entity Framwork模型。

你可能選擇「無身份驗證」,這就是爲什麼你沒有「Models/IdentityModel.cs」文件

1

我找不到他們參考,型號/ IdentityModel.cs文件。

generator-aspnet正在使用different version of templates而不是Visual C# Web Template shipped with Visual Studio 2015

文件Models/IdentityModel.cs應該包含類別ApplicationUserApplicationDbContext。它們與generator-aspnet使用的版本相同。

我把Model.cs的內容轉換成模型/ ApplicationUser.cs或 數據/ ApplicationDBContext.cs還是我留下的一切,是

你可以離開它,因爲它是 - 它這些文件位於哪裏並不重要。