0
將帖子添加到帖子存儲庫時,會發生以下消息:not null property references a null or transient value Category
。將實體添加到存儲庫時發生異常
[Test]
public void PostInsertion()
{
var category = new Category
{
Title = "Programming",
Description = "Programming"
};
var post = new Post
{
AuthorUrl = "some url",
Category = category,
Content = "some content",
Feedbacks = new HashedSet<Feedback>(),
Timestamp = DateTime.Now,
Title = "some title"
};
var postRepository = new Repository<Post>(this.sessionFactory);
postRepository.Add(post);
}
這是什麼意思?
編輯:郵政實體定義
[Serializable]
public class Post : Entity<Post>
{
public Post()
{
this.Feedbacks = new HashedSet<Feedback>();
}
public virtual String Title { get; set; }
public virtual String Content { get; set; }
public virtual DateTime Timestamp { get; set; }
public virtual Byte[] Thumbnail { get; set; }
public virtual Byte[] AuthorImg { get; set; }
public virtual String AuthorUrl { get; set; }
public virtual Category Category { get; set; }
public virtual ISet<Feedback> Feedbacks { get; set; }
public virtual void AddFeedback(Feedback feedback)
{
this.Feedbacks.Add(feedback);
}
}
謝謝!
你可以發佈Post的定義嗎? – 2011-12-28 10:38:46