我有这样的事情:
public class Category
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public List<Thread> Threads { get; set; }
}
public class Thread
{
[Key]
public int Id { get; set; }
public List<Post> Posts { get; set; }
}
public class Post
{
[Key]
public int Id { get; set; }
}
而且我不知道如何将线程项目添加到现有类别。我试过这样的事情:
var context = new Db();
var thr = new Thread
{...(adding new Post item here, not important since this works perfectly)...};
context.Categories.Single(c => c.Name == "some_category").Threads.Add(thr);
但这显然不想工作。