KISS Architecture (part 4)

by Chris 19. December 2008 15:59

In this part, I will get more practical by showing how the first parts of this architecture looks in code, and if you want some background, please see the previous parts:

  • Part 1 was a general introduction
  • Part 2 outlined the architecture (tiers, etc)
  • Part 3 showed the benefit of loosely coupled tiers (distribution, cloud, etc)

    As I mentioned in the first part, the implemented architecture is published on CodePlex in a project called KISS Architecture, and this means that you can access the full source code as well as discuss it, come with suggested improvements, etc. As I walk you through the creation of the architecture, I suggest you keep the source code handy to check out more details.

    Ok, let's start building the architecture from the ground up! To make things really simple (remember the KISS principle), I start with an "ASP.NET Web Application" named Kiss.Data as the data tier. In that assembly I add an "ADO.NET Entity Data Model" class named OrderModel.edmx, and add the following tables from the Northwind database (renamed Customer, Order, OrderDetail, Product and Category):

    KISS Architecture Entity Model

    If we take a look at a simplified version of the generated code (in OrderModel.Designer.cs)...

    namespace Kiss.Data
    {
       
    public partial class OrderEntities : ObjectContext
        {
           
    public OrderEntities(string connectionString) :
                base(connectionString, "OrderEntities")
            {
               
    this.OnContextCreated();
            }
           
    public ObjectQuery<Customer> CustomerSet
            {
               
    get
                {
                   
    if(this._CustomerSet == null)
                       
    this._CustomerSet =
                           
    base.CreateQuery<Customer>("[CustomerSet]");
                   
    return this._CustomerSet;
                }
            }
           
    private global::System.Data.Objects.ObjectQuery<Customer> _CustomerSet;
        }

        [
    EdmEntityTypeAttribute(NamespaceName = "Kiss.Data", Name = "Customer")]
        [
    DataContractAttribute(IsReference = true)]
        [
    Serializable()]
       
    public partial class Customer : EntityObject
        {
            [
    EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
            [
    DataMemberAttribute()]
           
    public string CustomerID
            {
               
    get { return this._CustomerID; }
               
    set
                {
                   
    this.OnCustomerIDChanging(value);
                   
    this.ReportPropertyChanging("CustomerID");
                   
    this._CustomerID = StructuralObject.SetValidValue(value, false);
                   
    this.ReportPropertyChanged("CustomerID");
                   
    this.OnCustomerIDChanged();
                }
            }
           
    private string _CustomerID;
           
    partial void OnCustomerIDChanging(string value);
           
    partial void OnCustomerIDChanged();

    ...we see that in the model, or object context, (OrderEntities) there is a class created for each entity (Customer) and a query (set) for that entity (CustomerSet). Also note that each of the entity classes and its members has the necessary decorations (attributes) to be serialized correctly over WCF.

    In the next part, I will look at how to publish the data model as a data service.

  • Currently rated 5.0 by 1 people

    • Currently 5/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Tags: , , ,

    Architecture | Chris | Compact Framework | Windows Mobile

    Comments

    Add comment


    (Will show your Gravatar icon)  

      Country flag

    biuquote
    • Comment
    • Preview
    Loading



    Powered by BlogEngine.NET 1.4.5.0
    Theme by Mads Kristensen