ADO.NET Data Services を使用してデータベースを更新しようとしています。
テーブル:
- Person( PK PersonId; FK EntityRootId)
- EntityRoot(PK EntityRootId、FK EntityTypeId)
- EntityTypes( PK EntityTypeId)
EntityRoot (Entity Framework の Entity と混同される可能性があるため、残念な名前です。EntityRoot は私のドメインにあります) を作成してデータベースに追加しようとしています。
var entRoot = EntityRoot.CreateEntityRoot(
0, "Lou", DateTime.Now, "Lou", DateTime.Now);
var entityType =
(from type in myContext.EntityTypeSet
where (type.Description == "Person")
select type).FirstOrDefault(); // this works fine and returns the entityType I’m looking for
entRoot.EntityType = entityType;
myContext.AddToEntityRootSet(entRoot);
// with the line below I get a runtime error:
// “AddLink and DeleteLink methods only work when the sourceProperty is a collection.”
//myContext.AddLink(entRoot, "EntityType", entityType);
// without the line above I get an error from the save:
// “Entities in 'MyEntities.EntityRootSet' participate in the 'FK_EntityRoots_EntityTypeId_Lookup_EntityTypes'
// relationship. 0 related 'EntityTypes' were found. 1 'EntityTypes' is expected.”
myContext.BeginSaveChanges(SaveChangesOptions.Batch,
new AsyncCallback(OnSaveAllComplete),
null);
entRoot.EntityTypeId フィールドへの参照を追加するにはどうすればよいですか?
これについての洞察に感謝します。