I generated a model (with EF) from my database ,i set Code Generation Strategy to None and then i created my (POCO) classes with the same properties as in model and now my business class are decoupled from EF. (My Model has only two classes:Question and Answer. One Question can have more Answers).
And this code is good:
Question q=db.Questions.First();
Answer a=q.Answers.First();
a.Title+=" modified";
q.Answers.Add(new Answer(){Text="bla bla bla"});
db.SaveChanges();
I have a little inconvenience:
Question q=db.Questions.First();
Answer a=q.Answers.First();
q.Answers.Remove(a);
db.SaveChanges();
With this code I have this error:
The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.
But this can be done with:
Question q=db.Questions.First();
Answer a=q.Answers.First();
db.Answers.DeleteObject(a);
So why do i need Castle Windsor(Dynamic Proxy) when my EF i good enough?EF works as well as Castle Windsor ,it inherit my POCO classes at Runtime.
1)What role have DynamicProxy(Castle Windsor) and AOP(PostSharp) if i have EF?
2)What do i need Dynamic Proxy(with reflection) when i can inherit my POCO classes at compiled time?(This is optional,possible to create another question for this subject)
Sorry for my bad English.