MySQL的实体框架 - 我究竟做错了什么? [英] MySQL with Entity Framework - what am I doing wrong?
问题描述
我是完全新的实体框架,甚至ADO.NET一般(通常不会做数据库的大量工作)。
- 我下载并安装的MySQL Connector / NET 6.3.5 。
- 我在Visual Studio 2010中创建一个新的C#项目。
- 我添加了一个新的ADO.NET实体数据模型到我的项目,并选择从数据库生成。
- 在我加入到我的本地MySQL服务器瓦特/服务器名localhost的+我的用户名和密码,一个新的连接。
- 在我检查所有的表从我的MySQL数据库生成对象的。
- 我写了下面code:
(的东西
只是一个假表我有一些任意字段扔在一起。)
TestDataEntities实体=新TestDataEntities();
VAR东西= entities.things.Execute(MergeOption.AppendOnly); // 例外
上面扔了的NullReferenceException
,我真的无言以对,为什么这可能是。当我测试连接,它说,它成功了。我已经肯定设置了正确的用户名和密码的连接。我甚至不知道还有什么调查。
对于那些你究竟是谁知道这个东西,这里的例外,我得到了(虽然我未受过训练的眼中,这实际上并不像它会是所有有用):
在MySql.Data.MySqlClient.MySqlClientFactory.get_MySqlDbProviderServicesInstance() 在MySql.Data.MySqlClient.MySqlClientFactory.System.IServiceProvider.GetService(类型的serviceType) 在System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory厂) 在System.Data.Metadata.Edm.StoreItemCollection.Loader.InitializeProviderManifest(Action`3 addError) 在System.Data.Metadata.Edm.StoreItemCollection.Loader.OnProviderManifestTokenNotification(字符串标记,Action`3 addError) 在System.Data.EntityModel.SchemaObjectModel.Schema.HandleProviderManifestTokenAttribute(XmlReader的读者) 在System.Data.EntityModel.SchemaObjectModel.Schema.HandleAttribute(XmlReader的读者) 在System.Data.EntityModel.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader的读者) 在System.Data.EntityModel.SchemaObjectModel.SchemaElement.Parse(XmlReader的读者) 在System.Data.EntityModel.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader的读者) 在System.Data.EntityModel.SchemaObjectModel.Schema.InternalParse(XmlReader的sourceReader,串sourceLocation) 在System.Data.EntityModel.SchemaObjectModel.Schema.Parse(XmlReader的sourceReader,串sourceLocation) 在System.Data.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders,IEnumerable`1 sourceFilePaths,SchemaDataModelOption数据模型,AttributeValueNotification providerNotification,AttributeValueNotification providerManifestTokenNotification,ProviderManifestNeeded providerManifestNeeded,IList`1&schemaCollection) 在System.Data.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders,IEnumerable`1 sourceFilePaths) 在System.Data.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders,IEnumerable`1文件路径,布尔throwOnError,DbProviderManifest和providerManifest,DbProviderFactory和providerFactory,Memoizer`2&cachedCTypeFunction) 在System.Data.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders,IEnumerable`1文件路径) 在System.Data.Metadata.Edm.MetadataCache.StoreMetadataEntry.LoadStoreCollection(EdmItemCollection edmItemCollection,MetadataArtifactLoader装载机) 在System.Data.Metadata.Edm.MetadataCache.StoreItemCollectionLoader.LoadItemCollection(StoreMetadataEntry条目) 在System.Data.Metadata.Edm.MetadataCache.LoadItemCollection [T](IItemCollectionLoader`1 itemCollectionLoader,T项) 在System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(字符串cacheKey,MetadataArtifactLoader装载机,EdmItemCollection edmItemCollection,对象和entryToken) 在System.Data.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace工作区,的DbConnection storeConnection,DbProviderFactory厂,DbConnectionOptions connectionOptions,EdmItemCollection edmItemCollection,MetadataArtifactLoader artifactLoader) 在System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(布尔initializeAllCollections) 在System.Data.EntityClient.EntityConnection.InitializeMetadata(的DbConnection newConnection,的DbConnection originalConnection,布尔closeOriginalConnectionOnFailure) 在System.Data.EntityClient.EntityConnection.Open() 在System.Data.Objects.ObjectContext.EnsureConnection() 在System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) 在System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption) 在EntityFrameworkTest.Form1..ctor()在D:\开发\ EntityFrameworkTest \ Form1.cs中:第23行 在EntityFrameworkTest.Program.Main()在D:\开发\ EntityFrameworkTest \的Program.cs:行18 在System.AppDomain._nExecuteAssembly(议会会议,字串[] args) 在System.AppDomain.ExecuteAssembly(字符串assemblyFile,证据assemblySecurity,字串[] args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象的状态) 在System.Threading.ThreadHelper.ThreadStart()
我通过增加提及MySql.Data.Entity.dll(和MySql.Web.dll)得到了过去的这个错误
I am completely new to Entity Framework and even ADO.NET in general (don't typically do much work with databases).
- I downloaded and installed MySQL Connector/NET 6.3.5.
- I created a new C# project in Visual Studio 2010.
- I added a new ADO.NET Entity Data Model to my project and chose "Generate from database."
- I added a new connection to my local MySQL server w/ server name "localhost" + my user name and password.
- I checked all of the tables from my MySQL database to generate objects for.
- I wrote the following code:
(things
is just a bogus table I threw together with some arbitrary fields.)
TestDataEntities entities = new TestDataEntities();
var things = entities.things.Execute(MergeOption.AppendOnly); // exception
The above threw a NullReferenceException
and I'm really clueless as to why that could be. When I test the connection, it says it succeeded. I have definitely set up the connection with the correct user name and password. I don't even know what else to investigate.
For those of you who actually know about this stuff, here's the exception I got (though, to my untrained eyes, this doesn't actually look like it would be all that helpful):
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()
I got past this error by adding a reference to MySql.Data.Entity.dll (and MySql.Web.dll)
这篇关于MySQL的实体框架 - 我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!