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