Note that there are some explanatory texts on larger screens.

plurals
  1. PORecommended structure for entity framework for a CRUD DAL for WCF
    primarykey
    data
    text
    <p>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.</p> <p>I see EF in Vs 2010 comes with three code-generator templates for EF:</p> <ol> <li><p><code>DbContext</code> generator, generates the context derived from <code>DbContext</code> and the entity classes as very simple POCO's with no extra code;</p> <pre><code>public partial class MyEntities : DbContext {...} </code></pre> <p>And entity classes</p> <pre><code>.... public int EmailAddressLocatorID { get; set; } .... public virtual Address Address { get; set; } .... public virtual ICollection&lt;HouseholdGuest&gt; HouseholdGuests { get; set; } </code></pre></li> <li><p><code>EntityObject</code> generator</p></li> <li><p>Self-tracking entity generator, that generates the context derived from <code>ObjectContext</code> and entities as POCO classes implementing <code>IObjectWithChangeTracker</code> and <code>INotifyPropertyChanged,</code> and helper class <code>ObjectChangeTracker</code> </p></li> </ol> <p>And I found another one on the internet, POCO entity generator, which generates the context based on <code>ObjectGenerator</code> and the entity classes as POCO with extra code for tracking navigation properties, as below:</p> <pre><code> public virtual ICollection&lt;Guest&gt; GuestsAddress { get { if (_guestsAddress == null) { var newCollection = new FixupCollection&lt;Guest&gt;(); newCollection.CollectionChanged += FixupGuestsAddress; _guestsAddress = newCollection; } return _guestsAddress; } set { if (!ReferenceEquals(_guestsAddress, value)) { var previousValue = _guestsAddress as FixupCollection&lt;Guest&gt;; if (previousValue != null) { previousValue.CollectionChanged -= FixupGuestsAddress; } _guestsAddress = value; var newValue = value as FixupCollection&lt;Guest&gt;; if (newValue != null) { newValue.CollectionChanged += FixupGuestsAddress; } } } } private ICollection&lt;Guest&gt; _guestsAddress; </code></pre> <p>where FixupCollection is a simple enhancement of <code>ObservableCollection</code>, implementing <code>ClearItems</code> and <code>InsertItem,</code> as below</p> <pre><code>public class FixupCollection&lt;T&gt; : ObservableCollection&lt;T&gt; { protected override void ClearItems() { new List&lt;T&gt;(this).ForEach(t =&gt; Remove(t)); } protected override void InsertItem(int index, T item) { if (!this.Contains(item)) { base.InsertItem(index, item); } } } </code></pre> <p>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.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload