Skip to content

Commit

Permalink
Added NuGet folder
Browse files Browse the repository at this point in the history
  • Loading branch information
markrendle committed Jan 21, 2011
1 parent ca3df19 commit bc29382
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 0 deletions.
Binary file added NuGet/NuGet.exe
Binary file not shown.
Binary file added NuGet/Simple.Data.Sample.0.4.4.nupkg
Binary file not shown.
7 changes: 7 additions & 0 deletions NuGet/Simple.Data.Sample/Content/App.config
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Simple.Data.Properties.Settings.DefaultConnectionString"
connectionString="data source=.\SQLSERVER2008;initial catalog=SimpleTest;integrated security=true" />
</connectionStrings>
</configuration>
117 changes: 117 additions & 0 deletions NuGet/Simple.Data.Sample/Content/DatabaseCreation.sql
@@ -0,0 +1,117 @@
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND type in (N'U'))
DROP TABLE [dbo].[Users];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[OrderItems]') AND type in (N'U'))
DROP TABLE [dbo].[OrderItems];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Orders]') AND type in (N'U'))
DROP TABLE [dbo].[Orders];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Items]') AND type in (N'U'))
DROP TABLE [dbo].[Items];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customers]') AND type in (N'U'))
DROP TABLE [dbo].[Customers];

CREATE TABLE [dbo].[Users] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (100) NOT NULL,
[Password] NVARCHAR (100) NOT NULL,
[Age] INT NOT NULL
);


CREATE TABLE [dbo].[Orders] (
[OrderId] INT IDENTITY (1, 1) NOT NULL,
[OrderDate] DATETIME NOT NULL,
[CustomerId] INT NOT NULL
);

ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED ([OrderId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);

CREATE TABLE [dbo].[OrderItems] (
[OrderItemId] INT IDENTITY (1, 1) NOT NULL,
[OrderId] INT NOT NULL,
[ItemId] INT NOT NULL,
[Quantity] INT NOT NULL
);

ALTER TABLE [dbo].[OrderItems]
ADD CONSTRAINT [PK_OrderItems] PRIMARY KEY CLUSTERED ([OrderItemId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);

CREATE TABLE [dbo].[Items] (
[ItemId] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (100) NOT NULL,
[Price] MONEY NOT NULL
);

ALTER TABLE [dbo].[Items]
ADD CONSTRAINT [PK_Items] PRIMARY KEY CLUSTERED ([ItemId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);

CREATE TABLE [dbo].[Customers] (
[CustomerId] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (100) NOT NULL,
[Address] NVARCHAR (200) NULL
);

ALTER TABLE [dbo].[Customers]
ADD CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED ([CustomerId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);

BEGIN TRANSACTION
SET IDENTITY_INSERT [dbo].[Customers] ON
INSERT INTO [dbo].[Customers] ([CustomerId], [Name], [Address]) VALUES (1, N'ACME', N'100 Road')
INSERT INTO [dbo].[Customers] ([CustomerId], [Name], [Address]) VALUES (2, N'Zenith', N'42 Street')
SET IDENTITY_INSERT [dbo].[Customers] OFF
SET IDENTITY_INSERT [dbo].[Orders] ON
INSERT INTO [dbo].[Orders] ([OrderId], [OrderDate], [CustomerId]) VALUES (1, '20101010 00:00:00.000', 1)
SET IDENTITY_INSERT [dbo].[Orders] OFF
SET IDENTITY_INSERT [dbo].[Items] ON
INSERT INTO [dbo].[Items] ([ItemId], [Name], [Price]) VALUES (1, N'Widget', 4.5000)
SET IDENTITY_INSERT [dbo].[Items] OFF
SET IDENTITY_INSERT [dbo].[OrderItems] ON
INSERT INTO [dbo].[OrderItems] ([OrderItemId], [OrderId], [ItemId], [Quantity]) VALUES (1, 1, 1, 10)
SET IDENTITY_INSERT [dbo].[OrderItems] OFF
SET IDENTITY_INSERT [dbo].[Users] ON
INSERT INTO [dbo].[Users] ([Id], [Name], [Password], [Age]) VALUES (1,'Bob','Secret',42)
INSERT INTO [dbo].[Users] ([Id], [Name], [Password], [Age]) VALUES (2,'Charlie','Squirrel',49)
INSERT INTO [dbo].[Users] ([Id], [Name], [Password], [Age]) VALUES (3,'Dave','Secret',42)
SET IDENTITY_INSERT [dbo].[Users] OFF

COMMIT TRANSACTION


ALTER TABLE [dbo].[Orders] WITH NOCHECK
ADD CONSTRAINT [FK_Orders_Customers] FOREIGN KEY ([CustomerId]) REFERENCES [dbo].[Customers] ([CustomerId]) ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE [dbo].[OrderItems] WITH NOCHECK
ADD CONSTRAINT [FK_OrderItems_Items] FOREIGN KEY ([ItemId]) REFERENCES [dbo].[Items] ([ItemId]) ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE [dbo].[OrderItems] WITH NOCHECK
ADD CONSTRAINT [FK_OrderItems_Orders] FOREIGN KEY ([OrderId]) REFERENCES [dbo].[Orders] ([OrderId]) ON DELETE NO ACTION ON UPDATE NO ACTION;

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCustomers]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetCustomers]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCustomerAndOrders]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetCustomerAndOrders]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCustomerCount]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetCustomerCount]
GO
CREATE PROCEDURE [dbo].[GetCustomers]
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM Customers
ORDER BY CustomerId
END
GO
CREATE PROCEDURE [dbo].[GetCustomerAndOrders] (@CustomerId int)
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM Customers WHERE CustomerId = @CustomerId;
SELECT * FROM Orders WHERE CustomerId = @CustomerId;
END
GO
CREATE PROCEDURE [dbo].[GetCustomerCount]
AS
BEGIN
SET NOCOUNT ON;
RETURN 1
END
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Simple.Data;

namespace $rootnamespace$.Samples
{
class CallingStoredProcedureExamples
{
public static void SimpleCallExample()
{
var db = Database.Open();
foreach (var customer in db.GetCustomers())
{
Console.WriteLine(customer.Name);
}
}

public static void ReturnValueExample()
{
var db = Database.Open();
int count = db.GetCustomerCount().ReturnValue;
}

public static void MultipleResultSetExample()
{
var db = Database.Open();
var results = db.GetCustomerAndOrders(1);
var customer = results.FirstOrDefault();

// Call NextResult on the results to move to the next result set, as with ADO DataReader
if (results.NextResult())
{
foreach (var order in results)
{
Console.WriteLine(order.OrderDate);
}
}
}
}
}
14 changes: 14 additions & 0 deletions NuGet/Simple.Data.Sample/Content/Samples/Customer.cs.pp
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace $rootnamespace$.Samples
{
class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
}
19 changes: 19 additions & 0 deletions NuGet/Simple.Data.Sample/Content/Samples/DeleteExamples.cs.pp
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using Simple.Data;

namespace $rootnamespace$.Samples
{
class DeleteExamples
{
public static void DeleteBy()
{
var db = Database.Open();
int deletedCount = db.Customers.DeleteById(3);
Console.WriteLine(deletedCount);
}
}
}
86 changes: 86 additions & 0 deletions NuGet/Simple.Data.Sample/Content/Samples/FindByExamples.cs.pp
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Simple.Data;

namespace $rootnamespace$.Samples
{
class FindByExamples
{
public static void AllExample()
{
var db = Database.Open(); // Opens the default database, as specified in config
foreach (var customer in db.Customers.All())
{
Console.WriteLine(customer.Name);
}

}
public static void BasicFindBy()
{
var db = Database.Open(); // Opens the default database, as specified in config
var customer = db.Customers.FindByCustomerId(1);
Console.WriteLine(customer.Name);
}

public static void TwoColumnFindBy()
{
var db = Database.Open();
var user = db.Users.FindByNameAndPassword("Bob", "Secret");
Console.WriteLine(user.Id);
}

public static void FindAllByReturnsMultipleRows()
{
var db = Database.Open();
foreach (var user in db.Users.FindAllByAge(42))
{
Console.WriteLine(user.Name + " is 42");
}
}

public static void FindWithOperators()
{
var db = Database.Open();
foreach (var user in db.Users.FindAll(db.Users.Age >= 40))
{
Console.WriteLine(user.Name + " is over 40");
}
/*
* Supported operators: ==, !=, <, <=, >, >=
*/
}

public static void FindWithMultipleOperators()
{
var db = Database.Open();
foreach (var user in db.Users.FindAll(db.Users.Age >= 40 && db.Users.Age < 50))
{
Console.WriteLine(user.Name + " is 40-something");
}
/*
* Supported operators: && and ||, and grouping using ()
*/
}

public static void FindWithLikeOperator()
{
var db = Database.Open();
foreach (var user in db.Users.FindAll(db.Users.Name.Like("B%")))
{
Console.WriteLine(user.Name + " starts with B");
}
/*
* NotLike("xyz") is also available
*/
}

public static void FindAcrossMultipleTablesWithForeignKeys()
{
// As long as a relationship is defined using a foreign key, you can find using criteria against related tables
var db = Database.Open();
var customersWhoHaveBoughtWidgets = db.Customers.Find(db.Customers.Orders.OrderItems.Item.Name == "Widget");
}
}
}
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Simple.Data;

namespace $rootnamespace$.Samples
{
class InferredHierarchyExample
{
/*
* When you've got foreign keys set up in your database, Simple.Data will try to infer
* object hierarchy for you from the schema
*/

public static void PrintCustomerOrders(int customerId)
{
var db = Database.Open();
var customer = db.Customers.FindByCustomerId(customerId);

foreach (var order in customer.Orders)
{
Console.WriteLine("Order {0} ({1})", order.OrderId, order.OrderDate);

foreach (var orderItem in order.OrderItems)
{
Console.WriteLine("\t{0} of {1} at {2} = {3}",
orderItem.Quantity, orderItem.Item.Name, orderItem.Item.Price, orderItem.Quantity * orderItem.Item.Price);
}
}

// This will only work with the dynamic type. Once you magic-cast into a static type,
// the lazy-loading stops.
}
}
}
40 changes: 40 additions & 0 deletions NuGet/Simple.Data.Sample/Content/Samples/InsertExamples.cs.pp
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using Simple.Data;

namespace $rootnamespace$.Samples
{
class InsertExamples
{
public static void InsertUsingNamedParameters()
{
var db = Database.Open();
var customer = db.Customers.Insert(Name: "Buy & Large", Address: "Outer Space");

// Because the Customer table has an Identity column, Simple.Data has returned the new row,
// including any default values set by the database.
Console.WriteLine(customer.CustomerId);
}

public static void InsertUsingExpandoObject()
{
dynamic customer = new ExpandoObject();
customer.Name = "Tyrell Corporation";
customer.Address = "New Los Angeles";
var db = Database.Open();
customer = db.Customers.Insert(customer);
}

public static void InsertUsingStaticTypedObject()
{
var customer = new Customer {Name = "SithCo", Address = "Tatooine"};
var db = Database.Open();
customer = db.Customers.Insert(customer);

// Magic implicit casting converts the dynamic object returned to the static type.
}
}
}

0 comments on commit bc29382

Please sign in to comment.