[英]Problems using MySQL with Entity Framework
I have a problem inserting a row using Entity Framework with the MySQL Connector/NET 6.4.4. 我在将实体框架与MySQL Connector / NET 6.4.4一起使用插入行时遇到问题。 When I try to save the changes after adding 1 row I get a System.NullReferenceException with the following stack-trace: 当我尝试添加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
I'm using EF 4.1 with "code first". 我将EF 4.1和“代码优先”一起使用。 In other words: I use DbSet and DbContext. 换句话说:我使用DbSet和DbContext。
This is what the entity I'm trying to add looks like in EF's change-tracker: 这就是我要添加的实体在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
Any ideas on what's causing this? 关于什么原因的任何想法? It looks like a bug in MySQL's EF-drivers (at least they should update then to provide a better error-message). 它看起来像是MySQL的EF驱动程序中的错误(至少它们应该先更新然后提供更好的错误消息)。
I had a similar problem, using the same connector driver. 使用相同的连接器驱动程序,我遇到了类似的问题。 In my case, one of the objects was using atributes instead of properties. 就我而言,其中一个对象使用属性而不是属性。
public class User : ProjectBasicEntity
{
public string SomeColumn;
}
Instead of 代替
public class User : ProjectBasicEntity
{
public string SomeColumn { get; set;}
}
I guess someone REALLY needs to improve the error handling in those drivers... 我猜确实有人需要改善这些驱动程序中的错误处理...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.