.
DevForce CodeFirst AOP rewrites your navigation properties, replacing your implementation with DevForce navigation logic.
[ProvideEntityAspect]
public class Foo
{
/*** Works and is the way we recommend ***/
public RelatedEntityList<Bar> Bars1 { get { return null; } } // no setter ... the way we recommend
/*** Works but prefer Bars1 ***/
public RelatedEntityList<Bar> Bars2 { get; set; } // the way you are tempted to write it
/*** Works but prefer Bars1 ***/
public ICollection<Bar> Bars3 { get; internal set; } // might be suitable for SL
/*** DO NOT DO ANY OF THE FOLLOWING ***/
public Foo()
{
/*
* Do not initialize navigation properties as this is neither effective
nor necessary.
*
* Many who come from EF or NHibernate
backgrounds think setting navigation properties
* makes Foo testable. This is a
misunderstanding about the difference between proxy and AOP.
* DevForce AOP collection navigation
properties are implemented and initialized
* wherever you use them ... including in testing.
*/
Bars3 = new RelatedEntityList<Bar>();
/* Backing fields are ignored by DevForce. */
_bars5 = new List<Bar>(); // typical EF/NH thinking
/* Backing fields are ignored by DevForce.
This won’t work */
_bars6Inner = new List<Bar>();
_bars6 = new ReadOnlyCollection<Bar>(_bars6Inner); // typical EF/NH thinking
}
/*** Does NOT work; DevForce won’t touch
private members ***/
public RelatedEntityList<Bar> Bars4 { get; private set; } // private setter
/*** “Works” but DevForce ignores the
backing field and it won’t change at runtime ***/
public ICollection<Bar> Bars5 // because the dev likes a backing field?
{
get { return _bars5; }
set { _bars5 = value; }
}
private ICollection<Bar> _bars5;
/*** “Works” but DevForce ignores the
backing field and it won’t change at runtime
and won’t be a ReadOnlyCollection as
you hoped ***/
public ICollection<Bar> Bars6 // observe how this is instantiated in ctor
{
get { return _bars6; }
set { _bars6 = value; }
}
private ICollection<Bar> _bars6;
private readonly IList<Bar> _bars6Inner;
}
[ProvideEntityAspect]
public class Bar { /* ... */ }