Как бы я вставил несколько строк в таблицу поиска с EF без получения этой ошибки: New transaction is not allowed because there are other threads running in the session
?
У меня есть таблица поиска PostTags, в которой я могу найти много тегов из сообщения, это то, что у меня есть в настоящее время для моего метода обновления, похоже, ошибка исходит из цикла foreach
, где я вставляю теги с использованием единицы работы, poco, шаблона репозитория ef 4 cpt5 в этом посте - Общая структура 4 CTP 4 / CTP 5 Entity Pattern и тестируемый модуль ):
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();
}
}
Спасибо.