1

ハイ、みんな!

VS2010 で EF 4.0 を使用し、MySQL をデータベースとして使用しています。抽象クラス (BaseEntity) と派生クラス (ChildEntity) があります。BaseEntity には Id プロパティ (PK) があり、ChildEntity にはもう 1 つのプロパティ (名前) があります。Table-Per-Type 戦略を使用しています。(ところで、エンティティマッピングを設定できますか?そのためのタブがあることは知っていますが、たとえばそこに新しいテーブルを追加できませんでした...)私の問題は、新しい ChildEntity をコンテキストに追加し、コンテキストを保存します (SaveChanges メソッド) NullReferenceException が発生します。私が使用するコード:

using (var oc = new ModelContext())
{
   ChildEntity child = ChildEntity.CreateChildEntity(1, "Name");
   oc.AddToBaseEntities(child);                
   oc.SaveChanges();
}

そして、ここに例外スタックトレースがあります:

System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  Source=MySql.Data.Entity
  StackTrace:
       at MySql.Data.Entity.InsertGenerator.GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning)
       at MySql.Data.Entity.InsertGenerator.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.Objects.ObjectContext.SaveChanges()
       at ConfigTool.Program.Main() in d:\dokumentumok\visual studio 2010\Projects\ConfigTool\ConfigTool\Program.cs:line 20
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

したがって、エラーはプロバイダーから発生します。投げられる理由がわかりました。モデルに継承を追加すると、BaseEntity と ChildEntity の間に PK-FK 制約という制約が作成されました。MySql プロバイダーはこの制約を満たしていないと思います。それで、私はこれについて何かをすることができますか、それとも継承の使用を忘れるべきですか? それとも、何かが足りないのでしょうか?ところで、具体的なタイプごとのテーブル戦略を行うにはどうすればよいですか? (ググって?)

プロバイダーとサーバーの最新の安定版を使用しています。

ご協力ありがとうございました。

Ps .: 編集 (または私の英語) に何か問題がありましたら申し訳ありません。

4

0 に答える 0