Skip to content

Commit

Permalink
Merge pull request #38 from jaredmoo/SampleImprovements
Browse files Browse the repository at this point in the history
Sample improvements
  • Loading branch information
jaredmoo committed Aug 30, 2015
2 parents e3981f1 + 7a954a6 commit 694e584
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 23 deletions.
13 changes: 0 additions & 13 deletions Samples/Dapper/App.config
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<!-- Set the following connection string to your local development database -->
<add name="DevelopmentDatabase" providerName="System.Data.SqlClient" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=elasticscaledev;Integrated Security=True" />
</connectionStrings>
</configuration>
17 changes: 15 additions & 2 deletions Samples/Dapper/ElasticDapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ElasticDapper</RootNamespace>
<AssemblyName>ElasticDapper</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Build.props))\Build.props" />
<!--
BUILD PROCESS FOR SAMPLES GALLERY
-->
<ItemGroup>
<!-- The file that gets transformed into the user's csproj when they create a new project from the samples gallery -->
<SamplesGalleryProjectInput Include="ElasticDapper.csproj.SamplesGallery" />
<!-- The file that gets transformed into the user's sln when they create a new project from the samples gallery -->
<SamplesGallerySolutionInput Include="ElasticDapper.sln.SamplesGallery" />
</ItemGroup>
<Import Project="..\SamplesGallery.targets" />
<!--
Any changes below must be copied to ShardSqlCmd.csproj.SamplesGallery, except:
- $(NugetPack) must be replaced with ..\packages
-->
<ItemGroup>
<Reference Include="$(NugetPack)\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll">
<Name>Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling</Name>
Expand All @@ -18,7 +31,7 @@
<Name>Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Data</Name>
</Reference>
<Reference Include="$(NugetPack)\Dapper.1.36\lib\net45\Dapper.dll">
<Name>$(NugetPack)\Dapper.1.36\lib\net45\Dapper.dll</Name>
<Name>Dapper</Name>
</Reference>
<Reference Include="$(NugetPack)\DapperExtensions.1.4.4\lib\net40\DapperExtensions.dll">
<Name>DapperExtensions</Name>
Expand Down
75 changes: 75 additions & 0 deletions Samples/Dapper/ElasticDapper.csproj.SamplesGallery
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AF5647D3-BB21-4708-897C-0066F3677B80}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ElasticDapper</RootNamespace>
<AssemblyName>ElasticDapper</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="..\packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll">
<Name>Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling</Name>
</Reference>
<Reference Include="..\packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\net45\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Data.dll">
<Name>Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Data</Name>
</Reference>
<Reference Include="..\packages\Dapper.1.36\lib\net45\Dapper.dll">
<Name>Dapper</Name>
</Reference>
<Reference Include="..\packages\DapperExtensions.1.4.4\lib\net40\DapperExtensions.dll">
<Name>DapperExtensions</Name>
</Reference>
<Reference Include="..\packages\Microsoft.Azure.SqlDatabase.ElasticScale.Client.1.0.0\lib\net45\Microsoft.Azure.SqlDatabase.ElasticScale.Client.dll">
<Name>Microsoft.Azure.SqlDatabase.ElasticScale.Client</Name>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataClasses.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sharding.cs" />
<Compile Include="SqlDatabaseUtils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="LICENSE" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
20 changes: 20 additions & 0 deletions Samples/Dapper/ElasticDapper.sln.SamplesGallery
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElasticDapper", "ElasticDapper\ElasticDapper.csproj", "{AF5647D3-BB21-4708-897C-0066F3677B80}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AF5647D3-BB21-4708-897C-0066F3677B80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF5647D3-BB21-4708-897C-0066F3677B80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF5647D3-BB21-4708-897C-0066F3677B80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF5647D3-BB21-4708-897C-0066F3677B80}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
42 changes: 34 additions & 8 deletions Samples/Dapper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public static void Main()
shardingLayer.RegisterNewShard(s_server, s_shard1, connStrBldr.ConnectionString, s_tenantId1);
shardingLayer.RegisterNewShard(s_server, s_shard2, connStrBldr.ConnectionString, s_tenantId2);

// Create schema on each shard.
foreach (string shard in new[] {s_shard1, s_shard2})
{
CreateSchema(shard);
}

// Do work for tenant 1 :-)
// For tenant 1, let's stay with plain vanilla Dapper
// and spell out the T-SQL we use to map into objects.
Expand All @@ -70,11 +76,7 @@ public static void Main()
options: ConnectionOptions.Validate))
{
var blog = new Blog { Name = name };
sqlconn.Execute(@"
INSERT INTO
Blog (Name)
VALUES (@name)", new { name = blog.Name }
);
sqlconn.Insert(blog);
}
});

Expand All @@ -87,9 +89,9 @@ INSERT INTO
{
// Display all Blogs for tenant 1
IEnumerable<Blog> result = sqlconn.Query<Blog>(@"
SELECT *
FROM Blog
ORDER BY Name");
SELECT *
FROM Blog
ORDER BY Name");

Console.WriteLine("All blogs for tenant id {0}:", s_tenantId1);
foreach (var item in result)
Expand Down Expand Up @@ -153,5 +155,29 @@ FROM Blog
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}

private static void CreateSchema(string shardName)
{
SqlConnectionStringBuilder connStrBldr = new SqlConnectionStringBuilder
{
UserID = s_userName,
Password = s_password,
ApplicationName = s_applicationName,
DataSource = s_server,
InitialCatalog = shardName
};

using (SqlConnection conn = new SqlConnection(connStrBldr.ToString()))
{
conn.Open();
conn.Execute(@"
IF (OBJECT_ID('[dbo].[Blog]', 'U') IS NULL)
CREATE TABLE [dbo].[Blog](
[BlogId] [int] IDENTITY(1,1) PRIMARY KEY,
[Name] [nvarchar](max) NULL,
[Url] [nvarchar](max) NULL,
)");
}
}
}
}
Binary file removed Samples/EFCodeFirst/EntityFrameworkCodeFirst.ico
Binary file not shown.
Binary file not shown.
Binary file removed Samples/ElasticScaleStarterKit/SampleApp.ico
Binary file not shown.
Binary file removed Samples/ShardSqlCmd/ShardSqlCmd.ico
Binary file not shown.

0 comments on commit 694e584

Please sign in to comment.