entity framework 4.1 - i am creating new database via code first and i got error the summary is below -


hello creating new database in sqlserver 2012 code first entity framework 4.1 error occurs system.data.sqlclient.sqlexception:invalid object name "dbo.blogs"

whole error summary below

system.data.entity.infrastructure.dbupdateexception unhandled   hresult=-2146233087   message=an error occurred while updating entries. see inner exception details.   source=entityframework   stacktrace:        @ system.data.entity.internal.internalcontext.savechanges()        @ system.data.entity.internal.lazyinternalcontext.savechanges()        @ system.data.entity.dbcontext.savechanges()        @ consoleapplication1.program.createblog() in c:\wcfserver\mt\pluralsight\consoleapplication1\program.cs:line 28        @ consoleapplication1.program.main(string[] args) in c:\wcfserver\mt\pluralsight\consoleapplication1\program.cs:line 15        @ system.appdomain._nexecuteassembly(runtimeassembly assembly, string[] args)        @ system.appdomain.executeassembly(string assemblyfile, evidence assemblysecurity, string[] args)        @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly()        @ system.threading.threadhelper.threadstart_context(object state)        @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)        @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)        @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state)        @ system.threading.threadhelper.threadstart()   innerexception: system.data.updateexception        hresult=-2146233087        message=an error occurred while updating entries. see inner exception details.        source=system.data.entity        stacktrace:             @ system.data.mapping.update.internal.updatetranslator.update(ientitystatemanager statemanager, ientityadapter adapter)             @ system.data.entityclient.entityadapter.update(ientitystatemanager entitycache)             @ system.data.objects.objectcontext.savechanges(saveoptions options)             @ system.data.entity.internal.internalcontext.savechanges()        innerexception: system.data.sqlclient.sqlexception             hresult=-2146232060             message=invalid object name 'dbo.blogs'.             source=.net sqlclient data provider             errorcode=-2146232060             class=16             linenumber=1             number=208             procedure=""             server=\\.\pipe\bbfc5858-2e09-44\tsql\query             state=1             stacktrace:                  @ system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)                  @ system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)                  @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose)                  @ system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready)                  @ system.data.sqlclient.sqldatareader.tryconsumemetadata()                  @ system.data.sqlclient.sqldatareader.get_metadata()                  @ system.data.sqlclient.sqlcommand.finishexecutereader(sqldatareader ds, runbehavior runbehavior, string resetoptionsstring)                  @ system.data.sqlclient.sqlcommand.runexecutereadertds(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, boolean async, int32 timeout, task& task, boolean asyncwrite)                  @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method, taskcompletionsource`1 completion, int32 timeout, task& task, boolean asyncwrite)                  @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method)                  @ system.data.sqlclient.sqlcommand.executereader(commandbehavior behavior, string method)                  @ system.data.sqlclient.sqlcommand.executedbdatareader(commandbehavior behavior)                  @ system.data.common.dbcommand.executereader(commandbehavior behavior)                  @ system.data.mapping.update.internal.dynamicupdatecommand.execute(updatetranslator translator, entityconnection connection, dictionary`2 identifiervalues, list`1 generatedvalues)                  @ system.data.mapping.update.internal.updatetranslator.update(ientitystatemanager statemanager, ientityadapter adapter)             innerexception:  

here code (domain class)

 using system;     using system.collections.generic;     using system.linq;     using system.text;      namespace domainclasses     {         public class blog         {             public int id { get; set; }             public string title { get; set; }             public string bloggername { get; set; }             public list<post> posts { get; set; }               public string blogcode             {                 { return title.substring(0, 1) + ":" + bloggername.substring(0, 1); }              }         }         public class post         {             public int id { get; set; }             public string title { get; set; }             public string content { get; set; }              public virtual blog blog { get; set; }         }         class program         {             static void main(string[] args)             {             }         }      } 

(context class)

    using system;     using system.collections.generic;     using system.linq;     using system.text;     using domainclasses;     using system.data.entity;     using system.diagnostics;     using system.data;     using system.configuration;       namespace datalayer     {        public class context:dbcontext        {                public dbset<blog> blogs { get; set; }             public dbset<post> posts { get; set; }             static void main(string[] args)             {              }     } } 

(console application)

 using system;     using system.collections.generic;     using system.linq;     using system.text;     using domainclasses;     using datalayer;     using system.io;      namespace consoleapplication1     {         class program         {             static void main(string[] args)             {             createblog();             }         private static void createblog()         {              using (var db = new context())             {                 blog blog = new blog { bloggername = "julie", title = "ef41 blog" };                   db.blogs.add(blog);                   db.savechanges();                 }         }     } } 

please me out waste 2 days error


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -