Exposing HasMany and ManyToMany relationships as IEnumerable

末鹿安然 提交于 2019-12-05 23:12:03
  1. Yes, if you expose an IEnumerable it is best to add methods on the class to handle Add/Remove
  2. A private backing field is a pretty good solution.
  3. Yes, but keep in mind if you want truly read only access to the exposed collection use ReadOnlyCollection - http://msdn.microsoft.com/en-us/library/ms132474.aspx

Agreed with Dan's answer, with a minor change:

public IEnumerable<OrderLine> OrderLines
{ get { return orderLines.Select(x => x; } }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!