Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I tend to lay my projects out as follows;</p> <p><strong>1) Presentation Layer:</strong></p> <pre><code>Contains my Views and ViewModels </code></pre> <p><strong>2) Business Layer:</strong></p> <pre><code>Contains my business logic </code></pre> <p><strong>3) Data Layer:</strong></p> <pre><code>Contains my models </code></pre> <hr> <p>My Presentation layer calls into the business layer to populate local copies (held in the ViewModel) of the data I wish to use in my ViewModel / View.</p> <p>This is achieved with a Using statement, something like;</p> <pre class="lang-vb prettyprint-override"><code>Using DBContext As Entities = ConnectToDatabase() Dim clsApprovalTypes As New Repositories.clsApprovalTypesRepository(DBContext) dbResults = clsApprovalTypes.GetRecords() End Using Return dbResults </code></pre> <p>Here I simply pass in the Context into Repository, once the data has been returned, the "End Using" will dispose of my context.</p> <p>To update the context with changes made in my ViewModel / View, I use an AddEdit routine, which accepts a record, and updates / Adds to the context as necessary, using a similar methodology to the above, something like;</p> <pre class="lang-vb prettyprint-override"><code>Using DBContext As CriticalPathEntities = ConnectToDatabase() Dim clsApprovalTypes As New Repositories.clsApprovalTypesRepository(DBContext) clsApprovalTypes.AddEditRecord(ApprovalTypeToSave) Try clsApprovalTypes.SaveData() Catch ex As Exception Return ex End Try End Using </code></pre> <p>Where my AddEdit routine is something like;</p> <pre class="lang-vb prettyprint-override"><code>SavedRecord = New ApprovalType 'Store the Saved Record for use later Dim query = From c In DBContext.ApprovalTypes Where c.ApprovalType_ID = RecordToSave.ApprovalType_ID Select c If query.Count &gt; 0 Then SavedRecord = query.FirstOrDefault End If ' ' Use Reflection here to copy all matching Properties between the Source Entity ' and the Entity to be Saved... ' SavedRecord = Classes.clsHelpers.CopyProperties(RecordToSave, SavedRecord) If query.Count = 0 Then Try DBContext.ApprovalTypes.Add(SavedRecord) Catch ex As EntityException Return ex End Try End If </code></pre> <p>I wrote a little more about some of this here;</p> <p><a href="https://stackoverflow.com/a/15014599/1305169">https://stackoverflow.com/a/15014599/1305169</a></p>
 

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