Last active
August 29, 2015 14:12
-
-
Save rcurlette/a1075062be4f26cf0693 to your computer and use it in GitHub Desktop.
ServiceStack ORMLite SqlServer example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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