Click here to Skip to main content
15,892,059 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 2 – Southwind Logic

Rate me:
Please Sign up or sign in to vote.
4.45/5 (6 votes)
15 Nov 2012LGPL325 min read 31.5K   1K   22  
In this part, we will focus on writing business logic, LINQ queries and explain inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Entities;
using Signum.Utilities;
using Signum.Entities.Basics;
using System.Data;

namespace Southwind.Entities
{
    [Serializable]
    public class EmployeeDN : Entity
    {
        [NotNullable, SqlDbType(Size = 20)]
        string lastName;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 20)]
        public string LastName
        {
            get { return lastName; }
            set { Set(ref lastName, value, () => LastName); }
        }

        [NotNullable, SqlDbType(Size = 10)]
        string firstName;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 10)]
        public string FirstName
        {
            get { return firstName; }
            set { Set(ref firstName, value, () => FirstName); }
        }

        [SqlDbType(Size = 30)]
        string title;
        [StringLengthValidator(AllowNulls = true, Min = 3, Max = 30)]
        public string Title
        {
            get { return title; }
            set { Set(ref title, value, () => Title); }
        }

        [SqlDbType(Size = 25)]
        string titleOfCourtesy;
        [StringLengthValidator(AllowNulls = true, Min = 3, Max = 25)]
        public string TitleOfCourtesy
        {
            get { return titleOfCourtesy; }
            set { Set(ref titleOfCourtesy, value, () => TitleOfCourtesy); }
        }

        DateTime? birthDate;
        [DateTimePrecissionValidator(DateTimePrecision.Hours)]
        public DateTime? BirthDate
        {
            get { return birthDate; }
            set { Set(ref birthDate, value, () => BirthDate); }
        }

        DateTime? hireDate;
        public DateTime? HireDate
        {
            get { return hireDate; }
            set { Set(ref hireDate, value, () => HireDate); }
        }

        AddressDN address;
        public AddressDN Address
        {
            get { return address; }
            set { Set(ref address, value, () => Address); }
        }

        [SqlDbType(Size = 25)]
        string homePhone;
        [StringLengthValidator(AllowNulls = true, Min = 3, Max = 25), TelephoneValidator]
        public string HomePhone
        {
            get { return homePhone; }
            set { Set(ref homePhone, value, () => HomePhone); }
        }

        [SqlDbType(Size = 4)]
        string extension;
        [StringLengthValidator(AllowNulls = true, Min = 3, Max = 4), TelephoneValidator]
        public string Extension
        {
            get { return extension; }
            set { Set(ref extension, value, () => Extension); }
        }

        [SqlDbType(Size = int.MaxValue)]
        byte[] photo;
        public byte[] Photo
        {
            get { return photo; }
            set { Set(ref photo, value, () => Photo); }
        }

        [SqlDbType(Size = int.MaxValue), ]
        string notes;
        [StringLengthValidator(AllowNulls = true, Min = 3, Max = int.MaxValue)]
        public string Notes
        {
            get { return notes; }
            set { Set(ref notes, value, () => Notes); }
        }

        Lite<EmployeeDN> reportsTo;
        public Lite<EmployeeDN> ReportsTo
        {
            get { return reportsTo; }
            set { Set(ref reportsTo, value, () => ReportsTo); }
        }

        [NotNullable, SqlDbType(Size = 255)]
        string photoPath;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 255), URLValidator]
        public string PhotoPath
        {
            get { return photoPath; }
            set { Set(ref photoPath, value, () => PhotoPath); }
        }

        MList<TerritoryDN> territories;
        public MList<TerritoryDN> Territories
        {
            get { return territories; }
            set { Set(ref territories, value, () => Territories); }
        }
    }

    [Serializable]
    public class TerritoryDN : IdentifiableEntity
    {
        RegionDN region;
        [NotNullValidator]
        public RegionDN Region
        {
            get { return region; }
            set { Set(ref region, value, () => Region); }
        }

        [NotNullable, SqlDbType(Size = 100), UniqueIndex]
        string description;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 100)]
        public string Description
        {
            get { return description; }
            set { SetToStr(ref description, value, () => Description); }
        }

        public override string ToString()
        {
            return description;
        }
    }

    [Serializable]
    public class RegionDN : IdentifiableEntity
    {
        [NotNullable, SqlDbType(Size = 50), UniqueIndex]
        string description;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 50)]
        public string Description
        {
            get { return description; }
            set { SetToStr(ref description, value, () => Description); }
        }

        public override string ToString()
        {
            return description;
        }
    }

    public enum EmployeeQueries
    {
        EmployeesByTerritory
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions