Permalink
Browse files

Changed MongoDb driver to Norm for full LINQ support.

  • Loading branch information...
1 parent abb5df2 commit a37dbd2eeca815a300117d6e8a7d1c9f8b7ece8c @primaryobjects committed Jan 6, 2012
View
@@ -7,3 +7,4 @@
*.exe.config
*.exe.manifest
!README.txt
+!lib/*.dll
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
+using System.Text;
+using Norm;
using MongoDragons.Repository.Context;
using MongoDragons.Types;
-using MongoDB;
namespace MongoDragons.Managers
{
@@ -1,73 +1,68 @@
-<?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>{3C7F45C2-42AA-4E30-B60F-B0BAE517F888}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>MongoDragons.Managers</RootNamespace>
- <AssemblyName>MongoDragons.Managers</AssemblyName>
- <TargetFrameworkVersion>v4.0</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="MongoDB, Version=0.90.0.1, Culture=neutral, PublicKeyToken=f61bd00ba2535278, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\MongoDragons\lib\MongoDB.dll</HintPath>
- </Reference>
- <Reference Include="MongoDB.Bson, Version=1.3.1.4349, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\..\..\..\..\Program Files (x86)\MongoDB\CSharpDriver 1.3.1\MongoDB.Bson.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <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="DragonManager.cs" />
- <Compile Include="HelperManager.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\MongoDragons.Repository\MongoDragons.Repository.csproj">
- <Project>{3732BBA1-6546-4ACF-9944-742FEBD0F023}</Project>
- <Name>MongoDragons.Repository</Name>
- </ProjectReference>
- <ProjectReference Include="..\MongoDragons.Types\MongoDragons.Types.csproj">
- <Project>{5F1D1B68-53E8-469D-BE22-08160A40DC9E}</Project>
- <Name>MongoDragons.Types</Name>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+<?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>{3C7F45C2-42AA-4E30-B60F-B0BAE517F888}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>MongoDragons.Managers</RootNamespace>
+ <AssemblyName>MongoDragons.Managers</AssemblyName>
+ <TargetFrameworkVersion>v4.0</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="Norm">
+ <HintPath>..\lib\Norm.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <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="DragonManager.cs" />
+ <Compile Include="HelperManager.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\MongoDragons.Repository\MongoDragons.Repository.csproj">
+ <Project>{3732BBA1-6546-4ACF-9944-742FEBD0F023}</Project>
+ <Name>MongoDragons.Repository</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\MongoDragons.Types\MongoDragons.Types.csproj">
+ <Project>{5F1D1B68-53E8-469D-BE22-08160A40DC9E}</Project>
+ <Name>MongoDragons.Types</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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">
</Target>
<Target Name="AfterBuild">
</Target>
- -->
+ -->
</Project>
@@ -1,88 +1,79 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using MongoDragons.Repository.Interface;
-using MongoDB.Driver;
-using MongoDragons.Repository.Helpers;
-using System.Configuration;
-using MongoDB.Driver.Builders;
-using MongoDB.Bson;
-
-namespace MongoDragons.Database.Concrete
-{
- public class MongoRepository : IRepository
- {
- private string _databaseName = "";
- private MongoServer _provider;
- private MongoDatabase _db { get { return this._provider.GetDatabase(_databaseName); } }
-
- public MongoRepository()
- {
- // Read the connection string from the web.config
- string connectionString = ConfigurationManager.ConnectionStrings["db"].ConnectionString;
-
- // Setup the provider.
- _provider = MongoServer.Create(connectionString);
- _databaseName = MongoUrl.Create(connectionString).DatabaseName;
- }
-
- public void Delete<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class, new()
- {
- var items = All<T>().Where(expression);
- foreach (T item in items)
- {
- Delete(item);
- }
- }
-
- public void Delete<T>(T item) where T : class, new()
- {
- // Get the Id value for the class.
- object value = GetPropValue(item, "Id");
-
- // Create the search query by Id.
- var query = Query.EQ("_id", ObjectId.Parse(value.ToString()));
-
- // Remove the object.
- _db.GetCollection<T>(typeof(T).Name).Remove(query);
- }
-
- public void DeleteAll<T>() where T : class, new()
- {
- _db.GetCollection<T>(typeof(T).Name).Drop();
- }
-
- public T Single<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class, new()
- {
- return All<T>().Where(expression).SingleOrDefault();
- }
-
- public IQueryable<T> All<T>() where T : class, new()
- {
- return _db.GetCollection<T>(typeof(T).Name).FindAll().AsQueryable();
- }
-
- public IQueryable<T> All<T>(int page, int pageSize) where T : class, new()
- {
- return PagingExtensions.Page(All<T>(), page, pageSize);
- }
-
- public void Add<T>(T item) where T : class, new()
- {
- _db.GetCollection<T>(typeof(T).Name).Save(item);
- }
-
- public void Add<T>(IEnumerable<T> items) where T : class, new()
- {
- foreach (T item in items)
- {
- Add(item);
- }
- }
-
- private object GetPropValue(object src, string propName)
- {
- return src.GetType().GetProperty(propName).GetValue(src, null);
- }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Configuration;
+using Norm;
+using MongoDragons.Repository.Interface;
+using MongoDragons.Repository.Helpers;
+
+namespace MongoDragons.Database.Concrete
+{
+ public class MongoRepository : IRepository
+ {
+ private IMongo _provider;
+ private IMongoDatabase _db { get { return this._provider.Database; } }
+
+ public MongoRepository()
+ {
+ _provider = Mongo.Create(ConfigurationManager.ConnectionStrings["db"].ConnectionString);
+ }
+
+ public void Delete<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class, new()
+ {
+ var items = All<T>().Where(expression);
+ foreach (T item in items)
+ {
+ Delete(item);
+ }
+ }
+
+ public void Delete<T>(T item) where T : class, new()
+ {
+ // Remove the object.
+ _db.GetCollection<T>().Delete(item);
+ }
+
+ public void DeleteAll<T>() where T : class, new()
+ {
+ _db.DropCollection(typeof(T).Name);
+ }
+
+ public T Single<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class, new()
+ {
+ return All<T>().Where(expression).SingleOrDefault();
+ }
+
+ public IQueryable<T> All<T>() where T : class, new()
+ {
+ return _db.GetCollection<T>().AsQueryable();
+ }
+
+ public IQueryable<T> All<T>(int page, int pageSize) where T : class, new()
+ {
+ return PagingExtensions.Page(All<T>(), page, pageSize);
+ }
+
+ public void Add<T>(T item) where T : class, new()
+ {
+ _db.GetCollection<T>().Save(item);
+ }
+
+ public void Add<T>(IEnumerable<T> items) where T : class, new()
+ {
+ foreach (T item in items)
+ {
+ Add(item);
+ }
+ }
+
+ public void Dispose()
+ {
+ _provider.Dispose();
+ }
+
+ private object GetPropValue(object src, string propName)
+ {
+ return src.GetType().GetProperty(propName).GetValue(src, null);
+ }
+ }
+}
@@ -4,7 +4,7 @@
namespace MongoDragons.Repository.Interface
{
- public interface IRepository
+ public interface IRepository : IDisposable
{
void Delete<T>(Expression<Func<T, bool>> expression) where T : class, new();
void Delete<T>(T item) where T : class, new();
Oops, something went wrong.

0 comments on commit a37dbd2

Please sign in to comment.