我知道没有N个具有相同标题的解决方案,并且经过3天无休止的运行,所有这些我都必须在此处发布。
我有一个像这样的UserDetailDAC.cs:-
public UserDetails ValidateUserAdmin(string Usrname, string pwd)
{
using (var db = new HostelManagementContext())
{
//IEnumerable<UserDetails> linq;
//string query = "SELECT* FROM UserDetails WHERE UserName ='" + Usrname + "' COLLATE SQL_Latin1_General_CP1_CS_AS AND UserPwd = '" + pwd + "' COLLATE SQL_Latin1_General_CP1_CS_AS";
//linq = db.Database.SqlQuery<UserDetails>(query);
//return linq.FirstOrDefault();
return db.Set<UserDetails>().Where(x => x.UserName == Usrname && x.UserPwd == pwd).FirstOrDefault();
}
}
和我的HostelManagementContext.cs一样:-
public HostelManagementContext() : base("ConnectionString")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<HostelManagementContext, HostelModel.Migrations.Configuration>("ConnectionString"));
//Database.SetInitializer<HostelManagementContext>(new DropCreateDatabaseIfModelChanges<HostelManagementContext>());
}
public DbSet<CandidateHostelBookingMapping> CandidateHostelBookingMappings { get; set; }
public DbSet<UserDetails> UserDetails { get; set; }
现在,当我尝试运行此命令时,出现以下错误:-
Cannot find the object "CandidateHostelBookingMappings" because it does not exist or you do not have permissions.
这是实体框架代码优先方法。请随时询问其他详细信息
答案 0 :(得分:0)
///您是否使用包迁移通过程序包管理器控制台创建数据库和表?
enable-migrations -ContextTypeName HostelManagementContext
add-migration -ConfigurationTypeName -----
update-database -ProjectName