c# - What are the Pros and Cons of having one-to-many bi-direcional relationships in Entity Framework (4.1)? -
i working on new project makes use of entity framework. in love relationship inverses, having navigation properties on both types make life easier. problem is: our project manager thinks using facility may lead mistakes , advising not use it.
let's have category , product:
public class product { public int id { get; set; } public string name { get; set; } public virtual category category { get; set; } } public class category { public int id { get; set; } public string name { get; set; } public virtual icollection<product> products { get; set; } }
he says 1 can, mistake, set productz.category categoryx , categoryy.products.add(productz), example. relationship persisted when save context? last one? ok, if first 1 correct category? , kind of error hard debug (which agree).
i don't think scenario can happen respect opinion, he's way more experienced me, want convince him let have bidirectional navigation properties , argument have is: if doing cannot bad. :)
can guys me more solid arguments?
one can mistake ...
one can write unit test validate code sets expected relations. can make mistake , removing navigation property not solution avoid problem. solution validate code expected = testing , code coverage.
what ask more designing classes - not mistakes. meaningful have navigation properties on both sides? adding product category or assigning category product? need offer both ways? can product exists without category? handling products , categories separately or aggregate? based on answers these questions can find navigation property on 1 side of relation not necessary.
Comments
Post a Comment