[英]MVC 5 C# web application
有人可以澄清這些事情嗎?
我還添加了一個名為DefaultConnection.cs
的上下文文件,其內容如下:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace Example.Models
{
public class DefaultConnection : DbContext
{
// You can add custom code to this file. Changes will not be overwritten.
// enter code here**`strong text`**
// If you want Entity Framework to drop and regenerate your database
// automatically whenever you change your model schema, please use data migrations.
// For more information refer to the documentation:
// http://msdn.microsoft.com/en-us/data/jj591621.aspx
public DefaultConnection()
: base("name=DefaultConnection")
{
}
public System.Data.Entity.DbSet<Exaple.Models.Book> Books { get; set; }
}
}
`
如果要使用另一個DbContext,另一個選擇是將屬性Table添加到Book類中:
[Table("Book")]
public class Book {....}
問候,
正如我在評論中提到的,您需要在ApplicationDbContext
定義您的Books
。 您無需創建其他上下文:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<Book> Books { get; set; }
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.