0

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.

Blocked
  • 340
  • 2
  • 5
  • 20
  • 1
    I think you are comparing three very different things that may have some overlapping features. For your use case, EF may be good enough. But that doesn't mean it covers all the use cases that Castle and PostSharp do. – Jason Apr 23 '13 at 16:47
  • Yes,it doesn't means.All that i need is to easy change my ORM.For this i have thought that might be need to use another component like PostSharp or Castle Windsor but it seem that EF has already this functionality(I guess that and NHiberante has similar functionality).Ok I think I have not researched enough.But now comes the second question:With inheritance at runtime we have slow the program and then i need inheritance at compiled time.How do i do this?Another solution is with the IL code Writter(PostSharp) but do i need to write for each setter and getter of my class? – Blocked Apr 23 '13 at 18:02

0 Answers0