I have something like this:
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; }
}
And i don’t know how to add a thread item to an existing category. I tried something like this:
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);
But this obviously doesn’t want to work.
Are you actually adding new Thread item to your context so that it’s tracked? If you’re context doesn’t know it exists, it won’t add it to the database.