Can somebody clarify those things:
I have also added a context file called DefaultConnection.cs
with the following content:
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; }
}
}
`
another option if you want yo use another DbContext, is add the attribute Table to the class Book:
[Table("Book")]
public class Book {....}
Regards,
As I mentioned in the comment, You need to define your Books
in ApplicationDbContext
. you don't need to create another context:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<Book> Books { get; set; }
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.