This feature allows you to represent the value of a table column as an enum in code, this is very useful when you have a foreign key relationship with values that will never change or not change often.

Step 1: Create Enum
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SauceExample
{
  public enum SauceEnum : int
  {
    Value1 = 1,
    Value2 = 2,
    Value3 = 3
  }
}

Step 2: Create Data Object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.Core.Attributes;

namespace SauceExample
{
  public class MyObject
  {
    public int id { get; set; }
    public SauceEnum EnumColumn { get; set; }
  }
}

Step 3: Use as normal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using DataAccess.Core;
using DataAccess.SqlServer;
using DataAccess.Core.Interfaces;

namespace SauceExample
{
  public class CrudClass
  {
    public static IDataStore _dstore; //I recommend keeping the reference around

    static CrudClass()
    {
      _dstore = SqlServerConnection.GetDataStore(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString);
    }

    [STAThread]
    public static void Main(string[] args)
    {
      //Table will be created and object inserted
      MyObject ToSave = new MyObject() { EnumColumn = SauceEnum.Value1 };
      _dstore.InsertObject(ToSave);

      //id property will be set on the object when done, so I can load based on that
      MyObject loaded = _dstore.LoadObject<MyObject>(ToSave.id);

      //update the name property
      loaded.EnumColumn = SauceEnum.Value2;

      //persist change
      _dstore.UpdateObject(loaded);
    }
  }
}

Screenshots of result
Note: No manual modification was done to sqlserver
Columns.PNG
Resultset.PNG

Last edited May 30, 2013 at 3:23 AM by iamkrillin, version 3

Comments

No comments yet.