C# 向成员资格数据库添加表
我正在使用会员数据库进行用户管理。 布局如下所示: 如您所见,我添加了一个新表“下载”。 在这个表中,我想存储一些附加信息 我上了一节课:C# 向成员资格数据库添加表,c#,sql,asp.net-membership,C#,Sql,Asp.net Membership,我正在使用会员数据库进行用户管理。 布局如下所示: 如您所见,我添加了一个新表“下载”。 在这个表中,我想存储一些附加信息 我上了一节课: public class DownloadInformation { public int Id { get; set;} public int UserId { get; set;} public string UserName { get; set;} public string Filename { get; set;
public class DownloadInformation
{
public int Id { get; set;}
public int UserId { get; set;}
public string UserName { get; set;}
public string Filename { get; set;}
public string UserIpAddress { get; set;}
public DateTime DownloadDate { get; set; }
}
在我的ApplicationDbContext中,我执行了以下操作:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var idUser = modelBuilder.Entity<IdentityUser>().ToTable("UserView");
idUser.Property(p => p.Id).HasColumnName("UserId");
idUser.Property(p => p.PasswordHash).HasColumnName("Password");
idUser.Property(p => p.SecurityStamp).HasColumnName("PasswordSalt");
idUser.Property(p => p.UserName).HasColumnName("UserName");
var appUser = modelBuilder.Entity<ApplicationUser>().ToTable("UserView");
appUser.Property(p => p.Id).HasColumnName("UserId");
appUser.Property(p => p.PasswordHash).HasColumnName("Password");
appUser.Property(p => p.SecurityStamp).HasColumnName("PasswordSalt");
appUser.Property(p => p.UserName).HasColumnName("UserName");
appUser.Property(p => p.Email).HasColumnName("Email");
var download = modelBuilder.Entity<DownloadInformation>().ToTable("Downloads");
download.Property(p => p.Id).HasColumnName("Id");
download.Property(p => p.UserId).HasColumnName("UserId");
download.Property(p => p.UserIpAddress).HasColumnName("UserIpAddress");
download.Property(p => p.UserName).HasColumnName("UserName");
download.Property(p => p.Filename).HasColumnName("Filename");
download.Property(p => p.DownloadDate).HasColumnName("DownloadDate");
}
}
using (ApplicationDbContext app = new ApplicationDbContext())
{
DownloadInformation downloadInfo = new DownloadInformation() { UserId = user.UserId, UserName = user.UserName, UserIpAddress = user.IpAddress, Filename = document.FilePath, DownloadDate = DateTime.Now };
app.Download.Add(downloadInfo);
app.SaveChanges();
}
编译此文件时,会出现以下错误:
“CustomerPortalDomain.Entities.ApplicationOndBContext”不包含“下载”的定义,并且找不到接受“CustomerPortalDomain.Entities.ApplicationOndBContext”类型的第一个参数的扩展方法“下载”(是否缺少using指令或程序集引用?)
我忘了什么?我遗漏了什么?看起来您没有向ApplicationDbContext添加任何“下载”属性
public DbSet<DownloadInformation> Download{ get; set; }
公共数据库集下载{get;set;}