c# - How do I construct a DbContext from an ObjectContext? -


i trying create constructor context class objectcontext. want because using devexpress xaf makes easy hold of objectcontext inside view.

the msdn here not include example

i have tried

public jobtalkdbcontext(objectcontext objectcontext) :        base(objectcontext.connection.connectionstring) { } 

however when try use context created way error message

system.data.entity.core.metadataexception unhandled user code hresult=-2146232007 message=at least 1 of input paths not valid because either long or has incorrect format. source=entityframework stacktrace:    @ system.data.entity.core.metadata.edm.metadataartifactloader.normalizefilepaths(string path)    @ system.data.entity.core.metadata.edm.metadataartifactloader.create(string path, extensioncheck extensioncheck, string validextension, icollection`1 uriregistry, metadataartifactassemblyresolver resolver)    @ system.data.entity.core.metadata.edm.metadataartifactloader.create(string path, extensioncheck extensioncheck, string validextension, icollection`1 uriregistry)    @ system.data.entity.core.metadata.edm.metadatacache.splitpaths(string paths)    @ system.data.entity.core.common.utils.memoizer`2.<>c__displayclass2.<evaluate>b__0()    @ system.data.entity.core.common.utils.memoizer`2.result.getvalue()    @ system.data.entity.core.common.utils.memoizer`2.evaluate(targ arg)    @ system.data.entity.core.metadata.edm.metadatacache.getartifactloader(dbconnectionoptions effectiveconnectionoptions)    @ system.data.entity.core.metadata.edm.metadatacache.getmetadataworkspace(dbconnectionoptions effectiveconnectionoptions)    @ system.data.entity.core.entityclient.entityconnection.getmetadataworkspace()    @ system.data.entity.core.objects.objectcontext.retrievemetadataworkspacefromconnection()    @ system.data.entity.core.objects.objectcontext..ctor(entityconnection connection, boolean isconnectionconstructor, objectqueryexecutionplanfactory objectqueryexecutionplanfactory, translator translator, columnmapfactory columnmapfactory)    @ system.data.entity.core.objects.objectcontext..ctor(entityconnection connection)    @ system.data.entity.internal.internalconnection.createobjectcontextfromconnectionmodel()    @ system.data.entity.internal.lazyinternalconnection.createobjectcontextfromconnectionmodel()    @ system.data.entity.internal.lazyinternalcontext.initializecontext()    @ system.data.entity.internal.internalcontext.initialize()    @ system.data.entity.internal.internalcontext.executesqlcommand(transactionalbehavior transactionalbehavior, string sql, object[] parameters)    @ system.data.entity.database.executesqlcommand(transactionalbehavior transactionalbehavior, string sql, object[] parameters)    @ system.data.entity.database.executesqlcommand(string sql, object[] parameters)    @ jobtalk.module.controllers.scheddatawork.clearallappointmentsandresources(jobtalkdbcontext connect) in c:\users\kirsten\documents\jtworkflow\jobtalk.module\controllers\scheddatawork.cs:line 86    @ jobtalk.module.controllers.scheddatawork.importappointmnentsfromtasks(iobjectspace objectspace) in c:\users\kirsten\documents\jtworkflow\jobtalk.module\controllers\scheddatawork.cs:line 57    @ jobtalk.module.win.controllers.listviewcontroller.actimportappointments_execute(object sender, simpleactionexecuteeventargs e) in c:\users\kirsten\documents\jtworkflow\jobtalk.module.win\controllers\listviewcontroller.cs:line 127    @ devexpress.expressapp.actions.simpleaction.raiseexecute(actionbaseeventargs eventargs)    @ devexpress.expressapp.actions.actionbase.executecore(delegate handler, actionbaseeventargs eventargs) innerexception: system.notsupportedexception    hresult=-2146233067    message=the given path's format not supported.    source=mscorlib    stacktrace:         @ system.security.util.stringexpressionset.canonicalizepath(string path, boolean needfullpath)         @ system.security.util.stringexpressionset.createlistfromexpressions(string[] str, boolean needfullpath)         @ system.security.permissions.fileiopermission.addpathlist(fileiopermissionaccess access, accesscontrolactions control, string[] pathlistorig, boolean checkforduplicates, boolean needfullpath, boolean copypathlist)         @ system.security.permissions.fileiopermission..ctor(fileiopermissionaccess access, string[] pathlist, boolean checkforduplicates, boolean needfullpath)         @ system.io.path.getfullpath(string path)         @ system.data.entity.core.metadata.edm.metadataartifactloader.normalizefilepaths(string path)    innerexception:  

i able create context using following methods.

public class jobtalkdbcontext : dbcontext {     public jobtalkdbcontext(string connectionstring)         : base(connectionstring) {             database.setinitializer(new jobtalkdbinitializer());     }      public jobtalkdbcontext(dbconnection connection)         : base(connection, false) {             database.setinitializer(new jobtalkdbinitializer());     }      public jobtalkdbcontext()  // used migrations         : base("name=applicationdatabase")     {         database.setinitializer(new jobtalkdbinitializer());     } } 

if want use existing objectcontext, proper constructor is

public jobtalkdbcontext(objectcontext objectcontext)      : base(objectcontext, false) { } 

where second argument in base constructor true if want objectcontext disposed dbcontext.

https://msdn.microsoft.com/en-us/library/dn220058(v=vs.113).aspx


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -