Click here to Skip to main content
15,891,939 members
Articles / Desktop Programming / Windows Forms

Code First: A Practical Case

Rate me:
Please Sign up or sign in to vote.
4.89/5 (19 votes)
26 Feb 2012CPOL15 min read 72.2K   3.7K   67  
A code first real life data model case
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xah.MediaCatalogerLib.Model.Files;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace Xah.MediaCatalogerLib.Model.Tracks
{
    //TODO: [Table("AudioTrackInfo")]
    public class AudioTrackInfo : BasicTrackInfo
    {
        public int Id { get; set; }

        public byte ChannelCount { get; set; }
        public int SamplingRate { get; set; }
        [Required]
        public virtual LanguageCode Language { get; set; }

        public AudioTrackInfo() { }

        public AudioTrackInfo(MediaCatalog db, MediaInfoLib.MediaInfo mi, int streamNumber)
            : base(mi, MediaInfoLib.StreamKind.Audio, streamNumber)
        {
            ChannelCount = mi.Get(MediaInfoLib.StreamKind.Audio, streamNumber, "Channel(s)").SafeConvertToByte();
            SamplingRate = mi.Get(MediaInfoLib.StreamKind.Audio, streamNumber, "SamplingRate").SafeConvertToInt32();
            Language = db.GetLanguageCode(mi.Get(MediaInfoLib.StreamKind.Audio, streamNumber, "Language"));
        }
    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Spain Spain
I studied Telecommunication with spezialization in Sound & Image. I was always very interested in programming at university as well and that is how I earn a living.

Since some years ago, I am also succesfully involved in software architecture and design.

Comments and Discussions