Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:32:13+00:00 2026-05-26T20:32:13+00:00

At present, I have very successfully architected my applications as follows: Data model (Entity

  • 0

At present, I have very successfully architected my applications as follows:

  • Data model (Entity Framework 4.1)

  • Validation using Enterprise Library 5.0 Validation Application Block.

  • Object Context managed by a reusable class library.

So, the UI is pretty light on code but I know I’m not completely there yet.

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?

Here’s some code, deliberately simplified, to illustrate my current state of play (I’ve omitted Code Contracts and the class libraries):

(Currently EF4 Model First and ASP .Net Web Forms)

Partial class for auto-generated entity

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<IMyEntity>()
                        .Validate(this));
            }
        }
    }
}

Validation

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);
    }
}

Facade for data access

namespace MyNamespace.Facade
{
    using System.Collections.Generic;
    using System.Linq;
    using Common.ObjectContextManagement;
    using Database;

    public sealed class MyEntityFacade : FacadeBase<MyEntities, MyEntity>
    {
        public IEnumerable<MyEntity> GetAll()
        {
            return this.ObjectContext.MyEntitys
                .Distinct()
                .ToList();
        }
    }
}

Web App UI

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);
        }
    }
}

How close am I?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:32:14+00:00Added an answer on May 26, 2026 at 8:32 pm

    The easiest way to expose your middle/backend so that a variety of clients can hook up is to wrap it all in one or more web services. In your example you can consider either exposing MyEntityFacade as a WCF service, or you can build an entirely new tier that passes back and forth between your client(s) and the facade.

    If you stick to POCO objects and SOAP, you can probably factor in connectivity from java, javascript, python, etc. in addition to your listed clients.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data I need to present to a user in a very
I have been very puzzled about the concept of model (entity) persistence in Symfony2.
I have just started developing using Youtube API and stuck in very beginning. I
I have a very simple setup, a whole solution that builds using .NET 3.5.
I currently have a very simple intranet that we are using for some basic
I have a very, very weird effect here using Monotouch 5.2.5 running my app
At present we have a denormalised database. ie Name|NameID|EmployeeID|EmployeeType I'm normalising the database to
I have to present some 'process' or 'flow' of the application at work on
I have an Excel application in which I want to present the user with
I have various time-series I'd like to correlate and present as either a csv-file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.