Skip to content

Instantly share code, notes, and snippets.

@rcurlette
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcurlette/a1075062be4f26cf0693 to your computer and use it in GitHub Desktop.
Save rcurlette/a1075062be4f26cf0693 to your computer and use it in GitHub Desktop.
ServiceStack ORMLite SqlServer example
using ServiceStack.DataAnnotations;
using ServiceStack.OrmLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public static string SqlServerBuildDb = "Server=Dev2011;Database=ItemInfoDb;User Id=NewDbUser;Password=S3cretPw;";
static void Main(string[] args)
{
ItemInfo itemPublishInfo = new ItemInfo();
itemPublishInfo.Title = "subject.Title";
itemPublishInfo.URI = "subject.Id";
SavePublishItemInDb(itemPublishInfo);
}
private static void SavePublishItemInDb(ItemInfo itemPublishInfo)
{
//Using SqlServer DB
var dbFactory = new OrmLiteConnectionFactory(
SqlServerBuildDb, SqlServerDialect.Provider);
using (var db = dbFactory.Open())
{
db.CreateTableIfNotExists<ItemInfo>();
// Insert
db.Insert(itemPublishInfo);
// Read
var allItems = db.Select<ItemInfo>();
}
}
public class ItemInfo
{
[AutoIncrement]
public int Id { get; set; }
public string Title { get; set; }
public string URI { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment