Following this question about the thread-safety of DbContext (it isn't), I need to know if it's safe to handle mapped POCOs in multiple threads.
Suppose I have two objects mapped to the database using CodeFirst:
class Poco1
{
public int Id { get; set; }
public string SomeProp {get; set;}
public virtual List<Poco2> children { get; set; }
}
class Poco2
{
public int id { get; set;}
public Poco1 parent { get; set; }
}
In the main thread I'm loading Poco1:
var parentPoco = _context.Poco1s.Where(...).Single();
I then pass it to a task, where I create another object and change the parent a bit
var childPoco = new Poco2 { parent=parentPoco };
parentPoco.SomeProp = "Tasked!";
Then back in the main thread I add childPoco to the context:
_context.Poco2s.Add(childPoco);
_context.SaveChanges();
I am not doing anything with the context in the secondary thread, but I am manipulating objects that are mapped to it.
Can I do that?