Click here to Skip to main content
11,490,408 members (48,546 online)
Click here to Skip to main content
Add your own
alternative version

Signum Framework Tutorials Part 2 – Southwind Logic

, 15 Nov 2012 LGPL3 13.3K 881 21
In this part, we will focus on writing business logic, LINQ queries and explain inheritance
Northwind.zip
Northwind.bak
SignumFramework2.0-src.zip
signumframework-signumframework-c6436e1
.gitignore
Local.testsettings
README.md
Signum.Engine
ClassDiagram1.cd
Connection
DynamicQuery
Engine
Linq
ExpressionVisitor
Meta
Properties
Schema
Schema.cd
SchemaBuilder
SignumFramework.pfx
Signum.Entities
Attributes.cd
Basics
ClassDiagram1.cd
Diagram.cd
DynamicQuery
Tokens
Patterns
Properties
Reflection
Services
SignumFramework.pfx
Signum.Framework.vsmdi
Signum.Test
ClassDiagram1.cd
LinqProvider
Properties
Settings.settings
Signum.Utilities
DataStructures
IntervalDictionaries
ExpressionTrees
Properties
Reflection
SignumFramework.pfx
Synchronization
Signum.Web
ButtonBar
ControllerAttributes
Facades
HtmlHelpers
JSRenderer
LineHelpers
Lines
Mappings
PortableAreas
Repositories
Properties
Signum
Content
Controllers
Images
asc.gif
calendar.png
desc.gif
lineButtons.gif
sign_error.gif
Models
Scripts
Views
Widgets
SignumFramework.pfx
TypeContext
Widgets
Signum.Windows
Basics
Controls
ColorUtils
Converters
DynamicQuery
EntityControls
Facades
Fluent
Images
admin.png
alert.png
calendar.png
cancel.png
close.png
entity.png
find.png
forbidden.png
newColumn.png
newFilter.png
note.png
ok.png
pin.png
reload.png
save.png
star.png
Localization
MarkupExtensions
Properties
SignumFramework.pfx
Themes
Utilities
Widgets
SignumFrameworkSetup
SignumFrameworkSetup.vdproj
logo.ico
signumFramework2.0.jpg
Snippets
DroidSansMono.ttf
RazorSingleFileGenerator.vsix
Signum.Fonts.vssettings
T4template
entity.snippet
entityWithName.snippet
expressionMethod.snippet
expressionMethodQuery.snippet
expressionProperty.snippet
field.snippet
fieldCreacion.snippet
fieldEuro.snippet
fieldInicioFin.snippet
fieldString.snippet
fiff.snippet
propiedad.snippet
tran.snippet
Template
EntityControlTemplate
MyTemplate.vstemplate
SignumEntityControl.zip
__TemplateIcon.ico
Template
MyTemplate.vstemplate
ProjectName.Entities
MyTemplate.vstemplate
Properties
__TemplateIcon.ico
ProjectName.Load
MyTemplate.vstemplate
Properties
Settings.settings
__TemplateIcon.ico
ProjectName.Logic
MyTemplate.vstemplate
Properties
__TemplateIcon.ico
ProjectName.Web
Code
Content
smoothness
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Controllers
Global.asax
MyTemplate.vstemplate
Properties
Settings.settings
Scripts
ServerCapri.svc
Views
Capri
Home
Shared
__TemplateIcon.ico
favicon.ico
ProjectName.Windows
Controls
MyTemplate.vstemplate
Properties
Settings.settings
__TemplateIcon.ico
SignumFramework2ClientServer.zip
__TemplateIcon.ico
WizardProjectName
Test
Properties
Settings.settings
WizardProjectName
Isolated
Properties
SignumFramework.pfx
TraceAndTestImpact.testsettings
SignumFramework2Setup.zip
SignumFramework2Setup.msi
Southwind-Part2-Logic.zip
.gitignore
README.md
Southwind.vssscc
Southwind
Southwind.Entities
Properties
Southwind.Load
Properties
Settings.settings
Southwind.Logic
Properties
Southwind.Web
Code
Content
smoothness
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Controllers
Global.asax
Properties
Settings.settings
Scripts
ServerSouthwind.svc
Views
Home
Shared
Southwind
favicon.ico
Southwind.Windows
Controls
Properties
Settings.settings
Southwind.zip
Southwind.bak
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Entities;
using System.Linq.Expressions;
using Signum.Utilities;

namespace Signum.Test
{
    [Serializable]
    public class NoteWithDateDN : Entity
    {
        [SqlDbType(Size = int.MaxValue)]
        string text;
        [StringLengthValidator(AllowNulls = false, Min = 3)]
        public string Text
        {
            get { return text; }
            set { SetToStr(ref text, value, () => Text); }
        }

        [ImplementedByAll]
        IIdentifiable target;
        public IIdentifiable Target
        {
            get { return target; }
            set { Set(ref target, value, () => Target); }
        }

        DateTime creationTime;
        public DateTime CreationTime
        {
            get { return creationTime; }
            set { Set(ref creationTime, value, () => CreationTime); }
        }

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

    [ImplementedBy(typeof(ArtistDN), typeof(BandDN))]
    public interface IAuthorDN : IIdentifiable
    {
        string Name { get; }

        AwardDN LastAward { get; }

        string FullName { get; }

        bool Lonely();
    }

    [Serializable]
    public class ArtistDN : Entity, IAuthorDN
    {
        [NotNullable, SqlDbType(Size = 100)]
        string name;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 100)]
        public string Name
        {
            get { return name; }
            set { SetToStr(ref name, value, () => Name); }
        }

        bool dead;
        public bool Dead
        {
            get { return dead; }
            set { Set(ref dead, value, () => Dead); }
        }

        Sex sex;
        public Sex Sex
        {
            get { return sex; }
            set { Set(ref sex, value, () => Sex); }
        }

        Status? status;
        public Status? Status
        {
            get { return status; }
            set { Set(ref status, value, () => Status); }
        }


        static Expression<Func<ArtistDN, bool>> IsMaleExpression = a => a.Sex == Sex.Male;
        public bool IsMale
        {
            get { return Sex == Sex.Male; }
        }

        [ImplementedByAll]
        AwardDN lastAward;
        public AwardDN LastAward
        {
            get { return lastAward; }
            set { Set(ref lastAward, value, () => LastAward); }
        }

        MList<Lite<ArtistDN>> friends;
        public MList<Lite<ArtistDN>> Friends
        {
            get { return friends; }
            set { Set(ref friends, value, () => Friends); }
        }

        static Expression<Func<ArtistDN, string>> FullNameExpression =
             a => a.Name + (a.Dead ? " Dead" : "") + (a.IsMale ? " Male" : " Female");
        public string FullName
        {
            get{ return FullNameExpression.Invoke(this); }
        }

        static Expression<Func<ArtistDN, bool>> LonelyExpression =
            a => !a.Friends.Any();
        public bool Lonely()
        {
            return LonelyExpression.Invoke(this);
        }

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

    [Flags]
    public enum Sex
    {
        Male,
        Female
    }

    public enum Status
    {
        Single,
        Married, 
    }

    [Serializable]
    public class BandDN : Entity, IAuthorDN
    {
        [NotNullable, SqlDbType(Size = 100), UniqueIndex]
        string name;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 100)]
        public string Name
        {
            get { return name; }
            set { SetToStr(ref name, value, () => Name); }
        }

        MList<ArtistDN> members;
        public MList<ArtistDN> Members
        {
            get { return members; }
            set { Set(ref members, value, () => Members); }
        }

        AwardDN lastAward;
        public AwardDN LastAward
        {
            get { return lastAward; }
            set { Set(ref lastAward, value, () => LastAward); }
        }

        MList<AwardDN> otherAwards;
        public MList<AwardDN> OtherAwards 
        {
            get { return otherAwards; }
            set { Set(ref otherAwards, value, () => OtherAwards); }
        }

        static Expression<Func<BandDN, string>> FullNameExpression =
            b => b.Name + " (" + b.Members.Count + " members )";
        public string FullName
        {
            get { return FullNameExpression.Invoke(this); }
        }

        static Expression<Func<BandDN, bool>> LonelyExpression =
            b => !b.Members.Any();
        public bool Lonely()
        {
            return LonelyExpression.Invoke(this);
        }

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

    [Serializable, ImplementedBy(typeof(GrammyAwardDN), typeof(AmericanMusicAwardDN))]
    public abstract class AwardDN : Entity
    {
        int year;
        public int Year
        {
            get { return year; }
            set { Set(ref year, value, () => Year); }
        }

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

        AwardResult result;
        public AwardResult Result
        {
            get { return result; }
            set { Set(ref result, value, () => Result); }
        }
    }

    public enum AwardResult 
    {
        Won,
        Nominated
    }

    [Serializable]
    public class GrammyAwardDN : AwardDN
    {
    }

    [Serializable]
    public class AmericanMusicAwardDN : AwardDN
    {
    }

    [Serializable]
    public class PersonalAwardDN : AwardDN
    {
    }


    [Serializable]
    public class LabelDN : Entity
    {
        [NotNullable, SqlDbType(Size = 100), UniqueIndex]
        string name;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 100)]
        public string Name
        {
            get { return name; }
            set { SetToStr(ref name, value, () => Name); }
        }

        CountryDN country;
        public CountryDN Country
        {
            get { return country; }
            set { Set(ref country, value, () => Country); }
        }

        Lite<LabelDN> owner;
        public Lite<LabelDN> Owner
        {
            get { return owner; }
            set { Set(ref owner, value, () => Owner); }
        }

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

    [Serializable]
    public class CountryDN : Entity
    {
        [NotNullable, SqlDbType(Size = 100), UniqueIndex]
        string name;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 100)]
        public string Name
        {
            get { return name; }
            set { SetToStr(ref name, value, () => Name); }
        }

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

    [Serializable]
    public class AlbumDN : Entity
    {
        [NotNullable, SqlDbType(Size = 100), UniqueIndex]
        string name;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 100)]
        public string Name
        {
            get { return name; }
            set { SetToStr(ref name, value, () => Name); }
        }

        int year;
        [NumberBetweenValidator(1900, 2100)]
        public int Year
        {
            get { return year; }
            set { Set(ref year, value, () => Year); }
        }

        IAuthorDN author;
        [NotNullValidator]
        public IAuthorDN Author
        {
            get { return author; }
            set { Set(ref author, value, () => Author); }
        }

        MList<SongDN> songs;
        public MList<SongDN> Songs
        {
            get { return songs; }
            set { Set(ref songs, value, () => Songs); }
        }

        SongDN bonusTrack;
        public SongDN BonusTrack
        {
            get { return bonusTrack; }
            set { Set(ref bonusTrack, value, () => BonusTrack); }
        }

        LabelDN label;
        public LabelDN Label
        {
            get { return label; }
            set { Set(ref label, value, () => Label); }
        }

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

    [Serializable]
    public class SongDN : EmbeddedEntity
    {
        [NotNullable, SqlDbType(Size = 100)]
        string name;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 100)]
        public string Name
        {
            get { return name; }
            set { SetToStr(ref name, value, () => Name); }
        }

        int? duration;
        [Unit("s")]
        public int? Duration
        {
            get { return duration; }
            set { Set(ref duration, value, () => Duration); }
        }

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

    [Serializable]
    public class AwardNominationDN : Entity
    {
        Lite<IAuthorDN> author;
        public Lite<IAuthorDN> Author
        {
            get { return author; }
            set { Set(ref author, value, () => Author); }
        }

        [ImplementedBy(typeof(GrammyAwardDN), typeof(PersonalAwardDN), typeof(AmericanMusicAwardDN))]
        Lite<AwardDN> award;
        public Lite<AwardDN> Award
        {
            get { return award; }
            set { Set(ref award, value, () => Award); }
        }

        int year;
        public int Year
        {
            get { return year; }
            set { Set(ref year, value, () => Year); }
        }
    }
}

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)

Share

About the Author

Olmo del Corral
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...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 15 Nov 2012
Article Copyright 2011 by Olmo del Corral
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid