I need to implement a back-office layer for an application. It will have to implement the data access through EF4, and expose the data access as CRUD through WCF services. The using of WCF Data Service is not an option, because the requirements are to expose a TCP service endpoint.
I see EF in Vs 2010 comes with three code-generator templates for EF:
DbContext
generator, generates the context derived fromDbContext
and the entity classes as very simple POCO's with no extra code;public partial class MyEntities : DbContext {...}
And entity classes
.... public int EmailAddressLocatorID { get; set; } .... public virtual Address Address { get; set; } .... public virtual ICollection<HouseholdGuest> HouseholdGuests { get; set; }
EntityObject
generatorSelf-tracking entity generator, that generates the context derived from
ObjectContext
and entities as POCO classes implementingIObjectWithChangeTracker
andINotifyPropertyChanged,
and helper classObjectChangeTracker
And I found another one on the internet, POCO entity generator, which generates the context based on ObjectGenerator
and the entity classes as POCO with extra code for tracking navigation properties, as below:
public virtual ICollection<Guest> GuestsAddress
{
get
{
if (_guestsAddress == null)
{
var newCollection = new FixupCollection<Guest>();
newCollection.CollectionChanged += FixupGuestsAddress;
_guestsAddress = newCollection;
}
return _guestsAddress;
}
set
{
if (!ReferenceEquals(_guestsAddress, value))
{
var previousValue = _guestsAddress as FixupCollection<Guest>;
if (previousValue != null)
{
previousValue.CollectionChanged -= FixupGuestsAddress;
}
_guestsAddress = value;
var newValue = value as FixupCollection<Guest>;
if (newValue != null)
{
newValue.CollectionChanged += FixupGuestsAddress;
}
}
}
}
private ICollection<Guest> _guestsAddress;
where FixupCollection is a simple enhancement of ObservableCollection
, implementing ClearItems
and InsertItem,
as below
public class FixupCollection<T> : ObservableCollection<T>
{
protected override void ClearItems()
{
new List<T>(this).ForEach(t => Remove(t));
}
protected override void InsertItem(int index, T item)
{
if (!this.Contains(item))
{
base.InsertItem(index, item);
}
}
}
I would like to ask for advise on which of them would be more appropriate for using to implement the CRUD over a WCF service, and some guidelines on best practices implementing this.
Thanks