c# - Invalid object name 'dbo.ApplicationUsers'.? -
i create small crud operation on user using entity framework code first.now need delete user using store procedure find many links getting solution how use store procedure in ef.so write code that.but m write code , method onmodelcreating() in class , go login time getting error 'invalid object name 'dbo.applicationusers'. comment method login work uncomment code getting error.
this class :
using system.security.claims; using system.threading.tasks; using microsoft.aspnet.identity; using microsoft.aspnet.identity.entityframework; using microsoft.aspnet.identity.owin; using system.data.entity; using system.data.entity.core.objects; using system.data.entity.infrastructure; using system.collections.generic; using system.componentmodel.dataannotations.schema; namespace abc.models { // can add profile data user adding more properties applicationuser class, please visit http://go.microsoft.com/fwlink/?linkid=317594 learn more. public class applicationuser : identityuser { public async task<claimsidentity> generateuseridentityasync(usermanager<applicationuser> manager, string authenticationtype) { // note authenticationtype must match 1 defined in cookieauthenticationoptions.authenticationtype var useridentity = await manager.createidentityasync(this, authenticationtype); // add custom user claims here return useridentity; } } public class applicationdbcontext : identitydbcontext<applicationuser> { public applicationdbcontext() : base("defaultconnection") { } public virtual dbset<users> users { get; set; } public static applicationdbcontext create() { return new applicationdbcontext(); } public virtual objectresult<list<users>> getuserinfo() { return ((iobjectcontextadapter)this).objectcontext.executefunction<list<users>>("getuserinfo"); } protected override void onmodelcreating(dbmodelbuilder modelbuilder) // method wroite after getting error { modelbuilder.entity<identityuserlogin>().haskey<string>(l => l.userid); modelbuilder.entity<identityrole>().haskey<string>(r => r.id); modelbuilder.entity<identityuserrole>().haskey(r => new { r.roleid, r.userid }); modelbuilder.entity<users>() .maptostoredprocedures(s => s.delete(u => u.hasname("deleteuserbyid", "dbo") .parameter(b => b.id, "userid")) ); } } }
this users class :
[table("users")] public class users { [key] [databasegeneratedattribute(databasegeneratedoption.none)] public long id { get; set; } public string firstname { get; set; } public string lastname { get; set; } public string contactnumber { get; set; } public datetime datetime { get; set; } }
this class 1 know how can , fix error.
the problem lies here
protected override void onmodelcreating(dbmodelbuilder modelbuilder) // method wroite after getting error { modelbuilder.entity<identityuserlogin>().haskey<string>(l => l.userid); modelbuilder.entity<identityrole>().haskey<string>(r => r.id); modelbuilder.entity<identityuserrole>().haskey(r => new { r.roleid, r.userid }); modelbuilder.entity<users>() .maptostoredprocedures(s => s.delete(u => u.hasname("deleteuserbyid", "dbo") .parameter(b => b.id, "userid")) ); }
remove first 3 lines , add
base.onmodelcreating(modelbuilder);
so be
protected override void onmodelcreating(dbmodelbuilder modelbuilder) { base.onmodelcreating(modelbuilder); modelbuilder.entity<users>() .maptostoredprocedures(s => s.delete(u => u.hasname("deleteuserbyid", "dbo") .parameter(b => b.id, "userid")) ); }
Comments
Post a Comment