سؤال

I believe this is a clear yes/no question I am asking, and regardless of implementation either it breaks the law or it does not. So my question is, do navigation properties created in the Entity Framework Model break The Law Of Demeter? I think they do because one entity could have far too much knowledge and access to its navigation property instances like below:

Orders.Products.Price

In the code above Orders in the main entity that contains a navigational property Products. Often we have to drill down through that navigation property to access details on that related object. I assume having instance properties in general also do not break the law correct?

Assistance on clearing this up will be helpful, thanks!

هل كانت مفيدة؟

المحلول

Yes they do but it doesn't matter. Strictly following Law of Demeter is almost impossible - you must do compromises to maintain high design quality, high code quality, maintainability and readability. EF puts additional requirements which are mostly related to the way how EF does the mapping between object and database record. Some types of mapping (EDMX) allows you to change visibility of entity properties so you can build your own abstraction layer on top of internal or protected properties but you can lost some EF features.

If you are interested in Law of Demeter and ORM tools you should also check Domain driven design and Aggregate roots.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top