0
このエラーを受け取らずに、EFでルックアップテーブルに複数の行を挿入するにはどうすればいいですか?New transaction is not allowed because there are other threads running in the session
?Entity Framework 4 CTP 5 POCO - ルックアップテーブルに複数の行を挿入しますか?
私は多くのタグが投稿のものであるポストタグルックアップテーブルを持っています。これは私の現在の更新メソッドにあります。エラーはforeach
ループから来ているようですこの記事での作業、POCOのユニット、EF 4 cpt5リポジトリパターン - Entity Framework 4 CTP 4/CTP 5 Generic Repository Pattern and Unit Testable):
if (ModelState.IsValid)
{
post.FriendlyUrl = Utils.ToFriendlyUrl(post.PostedDate.ToString("yyyy/MM/dd") + "/" + Utils.RemoveAccents(post.Title));
var tags = post.TagsString.TrimEnd(' ', ',').Split(',').ToList();
var updatePost = Mapper.Map<PostModel, Post>(post);
var postTags = new List<int>();
foreach (var tag in tags)
{
postTags.Add(_tag.CheckExistingTag(tag.Trim()));
}
_post.UpdatePost(updatePost);
_unitOfWork.Commit();
// Remove all existing tags associated with this post
_postTag.RemoveAllTagsInPost(updatePost.Id);
// Insert to the PostTagLookup table the new Tags that associates with this Post
foreach (var tagId in postTags)
{
var newPostTag = new PostTagLookup { PostId = updatePost.Id, TagId = tagId };
_postTag.Add(newPostTag);
_unitOfWork.Commit();
}
}
感謝。
こんにちはポール、私はとの問題を抱えた多対多の関係EFので、私はルックアップテーブルに行くことに決めました。ここで私の問題と同様に、多対多に関する私の最初の質問です:http://stackoverflow.com/questions/4571188/entity-framework-4-many-to-many-insertion and http://stackoverflow.com/questions/4589258/entity-framework-4-ctp-5-poco-many-to-many-or-lookup-tableを参照してください。 – Saxman