Permalink
Browse files

Added IDbContext interface and sample app updated

Sql Ce used for sample application
  • Loading branch information...
1 parent a5d5370 commit f607bde79ad8a1e6b6061c73c8af196e53e9f4df @ziyasal ziyasal committed Nov 2, 2012
Showing with 2,051 additions and 9 deletions.
  1. +6 −0 .nuget/NuGet.Config
  2. BIN .nuget/NuGet.exe
  3. +150 −0 .nuget/NuGet.targets
  4. +17 −0 RepositoryT.EntityFramework.ConsoleSample/App.config
  5. +22 −0 RepositoryT.EntityFramework.ConsoleSample/DataContextFactory.cs
  6. +33 −2 RepositoryT.EntityFramework.ConsoleSample/Program.cs
  7. +30 −2 RepositoryT.EntityFramework.ConsoleSample/RepositoryT.EntityFramework.ConsoleSample.csproj
  8. +1 −1 RepositoryT.EntityFramework.ConsoleSample/{RepoTContext.cs → SampleDataContext.cs}
  9. +2 −4 RepositoryT.EntityFramework.ConsoleSample/UserEntityRepository.cs
  10. +31 −0 RepositoryT.EntityFramework.ConsoleSample/UserService.cs
  11. +3 −0 RepositoryT.EntityFramework.ConsoleSample/packages.config
  12. +7 −0 RepositoryT.EntityFramework.sln
  13. +19 −0 RepositoryT.EntityFramework/IDbContext.cs
  14. +4 −0 RepositoryT.EntityFramework/RepositoryT.EntityFramework.csproj
  15. +8 −0 packages/Microsoft.SqlServer.Compact.4.0.8876.1/Content/web.config.transform
  16. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/Microsoft.SqlServer.Compact.4.0.8876.1.nupkg
  17. +14 −0 packages/Microsoft.SqlServer.Compact.4.0.8876.1/Microsoft.SqlServer.Compact.4.0.8876.1.nuspec
  18. +6 −0 ....SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest
  19. BIN ...ges/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/Microsoft.VC90.CRT/README_ENU.txt
  20. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/Microsoft.VC90.CRT/msvcr90.dll
  21. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/sqlceca40.dll
  22. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/sqlcecompact40.dll
  23. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/sqlceer40EN.dll
  24. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/sqlceme40.dll
  25. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/sqlceqp40.dll
  26. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/amd64/sqlcese40.dll
  27. +6 −0 ...ft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest
  28. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/Microsoft.VC90.CRT/README_ENU.txt
  29. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/Microsoft.VC90.CRT/msvcr90.dll
  30. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/sqlceca40.dll
  31. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/sqlcecompact40.dll
  32. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/sqlceer40EN.dll
  33. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/sqlceme40.dll
  34. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/sqlceqp40.dll
  35. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/NativeBinaries/x86/sqlcese40.dll
  36. +774 −0 packages/Microsoft.SqlServer.Compact.4.0.8876.1/SQLCE_EULA_ENU.rtf
  37. BIN packages/Microsoft.SqlServer.Compact.4.0.8876.1/lib/net40/System.Data.SqlServerCe.dll
  38. +201 −0 packages/Microsoft.SqlServer.Compact.4.0.8876.1/tools/Install.ps1
  39. +203 −0 packages/Microsoft.SqlServer.Compact.4.0.8876.1/tools/Uninstall.ps1
  40. +221 −0 packages/Microsoft.SqlServer.Compact.4.0.8876.1/tools/VS.psd1
  41. +276 −0 packages/Microsoft.SqlServer.Compact.4.0.8876.1/tools/VS.psm1
  42. BIN packages/SqlServerCompact.4.0.8854.1/SqlServerCompact.4.0.8854.1.nupkg
  43. +17 −0 packages/SqlServerCompact.4.0.8854.1/SqlServerCompact.4.0.8854.1.nuspec
View
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <solution>
+ <add key="disableSourceControlIntegration" value="true" />
+ </solution>
+</configuration>
View
Binary file not shown.
View
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
+
+ <!-- Enable the restore command to run before builds -->
+ <RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
+
+ <!-- Property that enables building a package from a project -->
+ <BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
+
+ <!-- Determines if package restore consent is required to restore packages -->
+ <RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
+
+ <!-- Download NuGet.exe if it does not already exist -->
+ <DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
+ </PropertyGroup>
+
+ <ItemGroup Condition=" '$(PackageSources)' == '' ">
+ <!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
+ <!--
+ <PackageSource Include="https://nuget.org/api/v2/" />
+ <PackageSource Include="https://my-nuget-source/nuget/" />
+ -->
+ </ItemGroup>
+
+ <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
+ <!-- Windows specific commands -->
+ <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
+ <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
+ </PropertyGroup>
+
+ <PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
+ <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
+ <NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
+ <PackagesConfig>packages.config</PackagesConfig>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <!-- NuGet command -->
+ <NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
+ <PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
+
+ <NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
+ <NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
+
+ <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
+
+ <RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
+ <!-- Commands -->
+ <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreCommand>
+ <BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
+
+ <!-- We need to ensure packages are restored prior to assembly resolve -->
+ <ResolveReferencesDependsOn Condition="$(RestorePackages) == 'true'">
+ RestorePackages;
+ $(ResolveReferencesDependsOn);
+ </ResolveReferencesDependsOn>
+
+ <!-- Make the build depend on restore packages -->
+ <BuildDependsOn Condition="$(BuildPackage) == 'true'">
+ $(BuildDependsOn);
+ BuildPackage;
+ </BuildDependsOn>
+ </PropertyGroup>
+
+ <Target Name="CheckPrerequisites">
+ <!-- Raise an error if we're unable to locate nuget.exe -->
+ <Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
+ <SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
+ <!--
+ Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
+ This effectively acts as a lock that makes sure that the download operation will only happen once and all
+ parallel builds will have to wait for it to complete.
+ -->
+ <MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT" />
+ </Target>
+
+ <Target Name="_DownloadNuGet">
+ <DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
+ </Target>
+
+ <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(RestoreCommand)"
+ Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
+
+ <Exec Command="$(RestoreCommand)"
+ LogStandardErrorAsError="true"
+ Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
+ </Target>
+
+ <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(BuildCommand)"
+ Condition=" '$(OS)' != 'Windows_NT' " />
+
+ <Exec Command="$(BuildCommand)"
+ LogStandardErrorAsError="true"
+ Condition=" '$(OS)' == 'Windows_NT' " />
+ </Target>
+
+ <UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
+ <ParameterGroup>
+ <OutputFilename ParameterType="System.String" Required="true" />
+ </ParameterGroup>
+ <Task>
+ <Reference Include="System.Core" />
+ <Using Namespace="System" />
+ <Using Namespace="System.IO" />
+ <Using Namespace="System.Net" />
+ <Using Namespace="Microsoft.Build.Framework" />
+ <Using Namespace="Microsoft.Build.Utilities" />
+ <Code Type="Fragment" Language="cs">
+ <![CDATA[
+ try {
+ OutputFilename = Path.GetFullPath(OutputFilename);
+
+ Log.LogMessage("Downloading latest version of NuGet.exe...");
+ WebClient webClient = new WebClient();
+ webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
+
+ return true;
+ }
+ catch (Exception ex) {
+ Log.LogErrorFromException(ex);
+ return false;
+ }
+ ]]>
+ </Code>
+ </Task>
+ </UsingTask>
+
+ <UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
+ <ParameterGroup>
+ <EnvKey ParameterType="System.String" Required="true" />
+ <EnvValue ParameterType="System.String" Required="true" />
+ </ParameterGroup>
+ <Task>
+ <Using Namespace="System" />
+ <Code Type="Fragment" Language="cs">
+ <![CDATA[
+ try {
+ Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
+ }
+ catch {
+ }
+ ]]>
+ </Code>
+ </Task>
+ </UsingTask>
+</Project>
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <configSections>
+ <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+ <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+ </configSections>
+ <connectionStrings>
+ <add name="SampleDataContext" connectionString="Data Source=|DataDirectory|\SampleDb.sdf" providerName="System.Data.SqlServerCe.4.0" />
+ </connectionStrings>
+ <entityFramework>
+ <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+ <parameters>
+ <parameter value="v11.0" />
+ </parameters>
+ </defaultConnectionFactory>
+ </entityFramework>
+</configuration>
@@ -0,0 +1,22 @@
+using RepositoryT.Infrastructure;
+
+namespace RepositoryT.EntityFramework.ConsoleSample
+{
+ public class DataContextFactory : IDataContextFactory<SampleDataContext>
+ {
+ private SampleDataContext _dataContext;
+
+ public SampleDataContext GetContext()
+ {
+ return _dataContext ?? (_dataContext = new SampleDataContext());
+ }
+
+ public void Dispose()
+ {
+ if (_dataContext != null)
+ {
+ _dataContext.Dispose();
+ }
+ }
+ }
+}
@@ -1,9 +1,40 @@
-namespace RepositoryT.EntityFramework.ConsoleSample
+using System;
+using RepositoryT.Infrastructure;
+
+namespace RepositoryT.EntityFramework.ConsoleSample
{
class Program
{
- static void Main(string[] args)
+ static void Main()
{
+ UserService userService = GetService();
+ userService.AddUser(new User
+ {
+ Email = "someone@somehost.com",
+ FirstName = "Ziyasal",
+ LastName = "XYZ"
+ });
+ userService.AddUser(new User
+ {
+ Email = "someone@somehost.com",
+ FirstName = "John",
+ LastName = "Doe"
+ });
+
+ foreach (User user in userService.GetAll())
+ {
+ Console.WriteLine("{0} {1}", user.FirstName, user.LastName);
+ }
+
+ Console.Read();
+ }
+
+ private static UserService GetService()
+ {
+ IDataContextFactory<SampleDataContext> dataContextFactory = new DataContextFactory();
+ IUserRepository userRepository = new UserEntityRepository(dataContextFactory);
+ IUnitOfWork uow = new UnitOfWork<SampleDataContext>(dataContextFactory);
+ return new UserService(uow, userRepository);
}
}
}
@@ -11,6 +11,8 @@
<AssemblyName>RepositoryT.EntityFramework.ConsoleSample</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -32,7 +34,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="EntityFramework">
+ <Reference Include="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="RepositoryT, Version=0.2.0.0, Culture=neutral, processorArchitecture=MSIL">
@@ -42,19 +45,27 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
+ <Reference Include="System.Data.Entity" />
+ <Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Runtime.Serialization" />
+ <Reference Include="System.Security" />
<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="DataContextFactory.cs" />
<Compile Include="IUserRepository.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="RepoTContext.cs" />
+ <Compile Include="SampleDataContext.cs" />
<Compile Include="User.cs" />
<Compile Include="UserEntityRepository.cs" />
+ <Compile Include="UserService.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RepositoryT.EntityFramework\RepositoryT.EntityFramework.csproj">
@@ -63,9 +74,26 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="SampleDb.sdf">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <PropertyGroup>
+ <PostBuildEvent>
+ if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
+ xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8876.1\NativeBinaries\x86\*.*" "$(TargetDir)x86"
+ if not exist "$(TargetDir)amd64" md "$(TargetDir)amd64"
+ xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8876.1\NativeBinaries\amd64\*.*" "$(TargetDir)amd64"</PostBuildEvent>
+ </PropertyGroup>
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
@@ -2,7 +2,7 @@
namespace RepositoryT.EntityFramework.ConsoleSample
{
- public class RepoTContext : DbContext
+ public class SampleDataContext : DbContext, IDbContext
{
public DbSet<User> Users { get; set; }
}
@@ -1,12 +1,10 @@
-using System;
-using System.Linq.Expressions;
using RepositoryT.Infrastructure;
namespace RepositoryT.EntityFramework.ConsoleSample
{
- public class UserEntityRepository : EntityRepository<User, RepoTContext>, IUserRepository
+ public class UserEntityRepository : EntityRepository<User, SampleDataContext>, IUserRepository
{
- public UserEntityRepository(IDataContextFactory<RepoTContext> databaseFactory)
+ public UserEntityRepository(IDataContextFactory<SampleDataContext> databaseFactory)
: base(databaseFactory)
{
}
@@ -0,0 +1,31 @@
+using System.Collections.Generic;
+using RepositoryT.Infrastructure;
+
+namespace RepositoryT.EntityFramework.ConsoleSample
+{
+ //Basic service class :) For detailed implementation look at:
+ //https://github.com/ziyasal/RepositoryT.RavenDb/tree/master/RepositoryT.RavenDb.Mvc4AutofacUOWSample/SampleBase
+ public class UserService
+ {
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IUserRepository _userRepository;
+
+ public UserService(IUnitOfWork unitOfWork, IUserRepository userRepository)
+ {
+ _unitOfWork = unitOfWork;
+ _userRepository = userRepository;
+ }
+
+ public int AddUser(User user)
+ {
+ _userRepository.Add(user);
+ _unitOfWork.Commit();
+ return user.Id;
+ }
+
+ public IEnumerable<User> GetAll()
+ {
+ return _userRepository.GetAll();
+ }
+ }
+}
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="EntityFramework" version="5.0.0" targetFramework="net40" />
+ <package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net40" />
<package id="RepositoryT" version="0.2.0" targetFramework="net40" />
+ <package id="SqlServerCompact" version="4.0.8854.1" targetFramework="net40" />
</packages>
Oops, something went wrong.

0 comments on commit f607bde

Please sign in to comment.