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)
    {
      for (int i = 0; i < 10; i++) //create ten objects
        _dstore.InsertObject(new MyObject() { Name = Guid.NewGuid().ToString() });

      //Load the entire table back
      IList<MyObject> items = _dstore.LoadEntireTable<MyObject>();
    }
  }
}

Note: The insert loop there will insert one object at at time, this can be somewhat inefficient since each object requires a roundtrip to the data store, however, there is a better way Insert Many Objects at once

Last edited May 30, 2013 at 4:19 AM by iamkrillin, version 4

Comments

No comments yet.