Note that there are some explanatory texts on larger screens.

plurals
  1. POWiring up any UI to my application
    primarykey
    data
    text
    <p>At present, I have very successfully architected my applications as follows:</p> <ul> <li><p>Data model (Entity Framework 4.1)</p></li> <li><p>Validation using Enterprise Library 5.0 Validation Application Block.</p></li> <li><p>Object Context managed by a reusable class library.</p></li> </ul> <p>So, the UI is pretty light on code but I know I'm not completely there yet.</p> <p><strong>If I wanted to have my projects set up so I could implement a Web Forms, MVC, WPF Desktop or Silverlight - even Windows Phone 7 - application, what additional steps might I need to take?</strong></p> <p>Here's some code, deliberately simplified, to illustrate my current state of play (I've omitted Code Contracts and the class libraries):</p> <p>(Currently EF4 Model First and ASP .Net Web Forms)</p> <p><strong>Partial class for auto-generated entity</strong></p> <pre><code>namespace MyNamespace.Database { using Microsoft.Practices.EnterpriseLibrary.Validation; using Microsoft.Practices.EnterpriseLibrary.Validation.Validators; [HasSelfValidation] public partial class MyEntity : IMyEntity { [SelfValidation] public void Validate(ValidationResults validationResults) { // Custom validation can go here, just add a new ValidationResult // to validationResults if the rule fails. if (validationResults != null) { validationResults.AddAllResults( ValidationFactory .CreateValidator&lt;IMyEntity&gt;() .Validate(this)); } } } } </code></pre> <p><strong>Validation</strong></p> <pre><code>namespace MyNamespace.Database { using System.ComponentModel.DataAnnotations; using System.Diagnostics.Contracts; using Microsoft.Practices.EnterpriseLibrary.Validation; using Microsoft.Practices.EnterpriseLibrary.Validation.Validators; [ContractClass(typeof(MyEntityContract))] public interface IMyEntity { int Id { get; set; } [Required] [NotNullValidator] [StringLengthValidator(0, RangeBoundaryType.Ignore, 50, RangeBoundaryType.Inclusive, MessageTemplate = "MyEntity Name must be 50 characters or less.")] string Name { get; set; } void Validate(ValidationResults validationResults); } } </code></pre> <p><strong>Facade for data access</strong></p> <pre><code>namespace MyNamespace.Facade { using System.Collections.Generic; using System.Linq; using Common.ObjectContextManagement; using Database; public sealed class MyEntityFacade : FacadeBase&lt;MyEntities, MyEntity&gt; { public IEnumerable&lt;MyEntity&gt; GetAll() { return this.ObjectContext.MyEntitys .Distinct() .ToList(); } } } </code></pre> <p><strong>Web App UI</strong></p> <pre><code>using (new UnitOfWorkScope(false)) { this.MyEntityList.DataSource = new MyEntityFacade().GetAll(); this.MyEntityList.DataBind(); } // Or... using (var scope = new UnitOfWorkScope(false)) { var myEntityFacade = new MyEntityFacade(); var myEntity = new MyEntity(); PopulateEntity(myEntity); // Validation errors are automatically presented // to the user from the Validate method if (Validate(myEntity)) { try { myEntityFacade.Add(myEntity); scope.SaveAllChanges(); } catch (Exception exception) { Logging.Write("Error", LoggingLevel.Error, exception.Message); } } } </code></pre> <p>How close am I?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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