我又遇到了 NHibernate 的一些问题。我想同时将两个子对象添加到父对象。问题是只有第一个孩子被提交,第二个孩子被忽略。我什至没有收到第二个孩子的错误消息。
public void CreateKeyword(CreateKeywordRequest request)
{
Collection collection = _collectionRepository.FindCollection(request.IdentityToken, request.CollectionName);
collection.AddKeyword(request.CategoryName, request.KeywordName, request.KeywordDescription);
_uow.Commit();
}
-
public void AddKeyword(string categoryName, string keywordName, string keywordDescription)
{
Category category = Categories.Where(c => c.CategoryName == categoryName).FirstOrDefault();
Keyword keyword = new Keyword { Category = category, KeywordName = keywordName, Description = keywordDescription };
category.Keywords.Add(keyword);
Test testOne= new Test{ Keyword = keyword, name = "test1" };
Test testTwo= new Test{ Keyword = keyword, name = "test2" };
//Only testOne gets committed and testTwo gets ignored
keyword.Tests.Add(testOne);
keyword.Tests.Add(testTwo);
ThrowExceptionIfKeywordIsInvalid(keyword);
}