我对Entity Framework甚至ADO.NET都是全新的(通常不会对数据库做太多工作)。
(things
只是一个虚假的表格,我和一些任意字段一起扔了。)
TestDataEntities entities = new TestDataEntities();
var things = entities.things.Execute(MergeOption.AppendOnly); // exception
上面提出了一个NullReferenceException
,我真的很无知为什么会这样。当我测试连接时,它说它成功了。我肯定使用正确的用户名和密码建立连接。我甚至不知道还有什么可以调查。
对于那些真正了解这些东西的人来说,这是我得到的例外(但是,对于我未经训练的人来说,这实际上看起来并没有那么有用):
at MySql.Data.MySqlClient.MySqlClientFactory.get_MySqlDbProviderServicesInstance() at MySql.Data.MySqlClient.MySqlClientFactory.System.IServiceProvider.GetService(Type serviceType) at System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory factory) at System.Data.Metadata.Edm.StoreItemCollection.Loader.InitializeProviderManifest(Action`3 addError) at System.Data.Metadata.Edm.StoreItemCollection.Loader.OnProviderManifestTokenNotification(String token, Action`3 addError) at System.Data.EntityModel.SchemaObjectModel.Schema.HandleProviderManifestTokenAttribute(XmlReader reader) at System.Data.EntityModel.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader) at System.Data.EntityModel.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader) at System.Data.EntityModel.SchemaObjectModel.SchemaElement.Parse(XmlReader reader) at System.Data.EntityModel.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader) at System.Data.EntityModel.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation) at System.Data.EntityModel.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation) at System.Data.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) at System.Data.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths) at System.Data.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, Memoizer`2& cachedCTypeFunction) at System.Data.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths) at System.Data.Metadata.Edm.MetadataCache.StoreMetadataEntry.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader) at System.Data.Metadata.Edm.MetadataCache.StoreItemCollectionLoader.LoadItemCollection(StoreMetadataEntry entry) at System.Data.Metadata.Edm.MetadataCache.LoadItemCollection[T](IItemCollectionLoader`1 itemCollectionLoader, T entry) at System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken) at System.Data.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace workspace, DbConnection storeConnection, DbProviderFactory factory, DbConnectionOptions connectionOptions, EdmItemCollection edmItemCollection, MetadataArtifactLoader artifactLoader) at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) at System.Data.EntityClient.EntityConnection.InitializeMetadata(DbConnection newConnection, DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure) at System.Data.EntityClient.EntityConnection.Open() at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption) at EntityFrameworkTest.Form1..ctor() in D:\Development\EntityFrameworkTest\Form1.cs:line 23 at EntityFrameworkTest.Program.Main() in D:\Development\EntityFrameworkTest\Program.cs:line 18 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
答案 0 :(得分:14)
我通过添加对MySql.Data.Entity.dll(和MySql.Web.dll)的引用来解决此错误
答案 1 :(得分:2)
这是一个提供程序错误。它可能是由配置错误触发的错误,但它仍然是提供程序错误。您应该与编写MySQL提供程序的人员交谈,并向他们发送堆栈和测试用例。
答案 2 :(得分:2)
答案 3 :(得分:1)
好吧,我不知道这是不是应该是这样的方式(如果是的话,我有点尴尬 - 虽然在我的防守中我看不到任何明显的指示);但似乎问题是我的目标框架设置为.NET 3.5 。在将项目的目标框架(老实说,一时兴起)更改为.NET 4.0之后,NullReferenceException
消失了。
所以,尽管不尽如人意,但这似乎是我个案的解决方案。
答案 4 :(得分:1)
在MySqlClientFactory-> MySqlDbProviderServicesInstance属性。 它引用了ass:MySql.Data.Entity使用代码
string str = Assembly.GetExecutingAssembly().FullName.Replace("MySql.Data", "MySql.Data.Entity");
但是在MySql Client 6.3.5中,MySqlData的版本是6.3.5,而MySql.Data.Entity的版本是6.3.4(在\ Program Files \ MySQL \ MySQL Connector Net 6.3.5 \ Assemblies \ v2.0中) )。所以它无法成功加载。
在文件夹(\ Program Files \ MySQL \ MySQL Connector Net 6.3.5 \ Assemblies \ v4.0)中,MySql.Data.Entity的版本为6.3.5,因此可以加载成功。
所以一种方法是将目标更改为.NET 4.0,另一种方法是将MySql.Data转回6.3.2 / 6.1.2。