C# 在实体框架中使用MySQL的问题

C# 在实体框架中使用MySQL的问题,c#,.net,mysql,entity-framework,connector-net,C#,.net,Mysql,Entity Framework,Connector Net,我在MySQL Connector/NET 6.4.4中使用实体框架插入行时遇到问题。当我尝试在添加1行后保存更改时,我得到一个System.NullReferenceException,具有以下堆栈跟踪: at MySql.Data.Entity.SqlGenerator.GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) at MySql.Data.Entity.UpdateGenerat

我在MySQL Connector/NET 6.4.4中使用实体框架插入行时遇到问题。当我尝试在添加1行后保存更改时,我得到一个System.NullReferenceException,具有以下堆栈跟踪:

at MySql.Data.Entity.SqlGenerator.GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) 
at MySql.Data.Entity.UpdateGenerator.GenerateSQL(DbCommandTree tree) 
at MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) 
at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree) 
at System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree) 
at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree) 
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues) 
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues) 
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) 
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) 
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) 
at System.Data.Entity.Internal.InternalContext.SaveChanges() 
at System.Data.Entity.Internal.LazyInternalContext.SaveChanges() 
at System.Data.Entity.DbContext.SaveChanges() 
at UserData.Repository.DBRepositoryDataContext.SaveChanges() in C:\SoftwareProjects\Java\Degoo\Server\UserData\Repository\DBRepositoryDataContext.cs:line 42 
at UserData.Repository.Repository.<SaveChanges>b__1() in C:\SoftwareProjects\Java\Degoo\Server\UserData\Repository\Repository.cs:line 137 
at Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling.RetryPolicy`1.ExecuteAction(Action action) in C:\SoftwareProjects\Java\Degoo\Server\Libraries\TransientFaultHandlingFramework\RetryPolicy.cs:line 352 
在MySql.Data.Entity.SqlGenerator.GenerateReturningSql(DbModificationCommandTree树,DbExpression返回)
在MySql.Data.Entity.UpdateGenerator.GenerateSQL(DbCommandTree树)
位于MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest,DbCommandTree commandTree)
位于System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
位于System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
位于System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
位于System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator,Dictionary`2 IdentifierValue)
在System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator转换器、EntityConnection连接、Dictionary`2 identifierValues、List`1 generatedValues)
位于System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntITYAAdapter适配器)
位于System.Data.EntityClient.EntityAdapter.Update(EntityStateManager entityCache)
位于System.Data.Objects.ObjectContext.SaveChanges(保存选项)
位于System.Data.Entity.Internal.InternalContext.SaveChanges()处
在System.Data.Entity.Internal.LazyInternalContext.SaveChanges()中
位于System.Data.Entity.DbContext.SaveChanges()处
在C:\SoftwareProjects\Java\Degoo\Server\UserData\Repository\DBRepositoryDataContext.cs中的UserData.repositorydatacontext.SaveChanges()处:第42行
在C:\SoftwareProjects\Java\Degoo\Server\UserData\Repository\Repository.cs中的UserData.Repository.b\uu 1()处:第137行
在C:\SoftwareProjects\Java\Degoo\Server\Libraries\TransientFaultHandlingFramework\RetryPolicy.cs中的Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling.RetryPolicy`1.ExecuteAction(Action-Action)中
我使用EF4.1和“代码优先”。换句话说:我使用DbSet和DbContext

这就是我试图添加的实体在EF的更改跟踪器中的外观:

     System.Data.Entity.Infrastructure.DbEntityEntry<Utilities.IStandardEntity> 
_internalEntityEntry    System.Data.Entity.Internal.InternalEntityEntry 
CurrentValues       System.Data.Entity.Infrastructure.DbPropertyValues 
Entity      UserData.PerformanceCounterEntities.PerformanceCounterEntity 
CallingClassName    "com.degoo.tests.integration.PerformanceCounterUploaderTest"    string 
Category    {System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C10C0AE9C5B35779176C02A53A587F1A} UserData.PerformanceCounterEntities.TextEntity {System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C10C0AE9C5B35779176C02A53A587F1A} 
CategoryTextID  1   long 
CreationTime    {2011-11-09 09:32:12}   System.DateTime 
Description {System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C10C0AE9C5B35779176C02A53A587F1A} UserData.PerformanceCounterEntities.TextEntity {System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C10C0AE9C5B35779176C02A53A587F1A} 
DescriptionTextID   3   long 
ID  0   long 
ModificationTime    {2011-11-09 09:32:12}   System.DateTime 
Name    {System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C10C0AE9C5B35779176C02A53A587F1A} UserData.PerformanceCounterEntities.TextEntity {System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C10C0AE9C5B35779176C02A53A587F1A} 
NameTextID  2   long 
NodeID  16485   long 
NumberOfSamples 1   long 
RowVersion  0   long 
Value   1.0 double
System.Data.Entity.Infrastructure.DbEntityEntry
_internalEntityEntry System.Data.Entity.Internal.internalEntityEntry
CurrentValues System.Data.Entity.Infrastructure.DbPropertyValues
实体UserData.PerformanceCounterEntity.PerformanceCounterEntity
调用ClassName“com.degoo.tests.integration.PerformanceCounterUploaderTest”字符串
类别{System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C1C00AE9C5B35779176C02A553A587F1A}UserData.PerformanceCounterties.TextEntity{System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C00AE9C55779176C02A587F1A}
CategoryTextID 1长
CreationTime{2011-11-09 09:32:12}System.DateTime
说明{System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C1C00AE9C5B35779176C02A553A587F1A}用户数据.PerformanceCounterties.TextEntity{System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C00AE9C55779176C02A587F1A}
descriptionContextId 3长
ID 0长
修改时间{2011-11-09 09:32:12}System.DateTime
名称{System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C1C00AE9C5B35779176C02A553A587F1A}UserData.PerformanceCounterties.TextEntity{System.Data.Entity.DynamicProxies.TextEntity_27BF3732ED645CE792F48B4AA75BFD05C00AE9C55779176C02A587F1A}
NameTextID 2长
诺德16485长
样本数1长
行版本0长
值1.0倍

你知道这是什么原因吗?这看起来像是MySQL的EF驱动程序中的一个bug(至少它们应该更新以提供更好的错误消息)。

我也遇到了类似的问题,使用了相同的连接器驱动程序。在我的例子中,其中一个对象使用atributes而不是properties

public class User : ProjectBasicEntity
{
   public string SomeColumn;
}
而不是

public class User : ProjectBasicEntity
{
   public string SomeColumn { get; set;}
}

我想有人真的需要改进这些驱动程序中的错误处理…

如果商业提供商/驱动程序是一个选项,请尝试Devart提供的一个-与EF()配合使用非常好。。。(只是一个快乐的客户,没有关联)