Skip to content

Commit

Permalink
Dev -> Trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
RobThree committed Oct 25, 2013
1 parent 70bb2ab commit ccb128a
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 86 deletions.
15 changes: 12 additions & 3 deletions MongoRepository/trunk/Help/MongoRepository.shfbproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
<OutputPath>Output\</OutputPath>
<HtmlHelpName>Documentation</HtmlHelpName>
<Language>en-US</Language>
<FrameworkVersion>.NET Framework 3.5</FrameworkVersion>
<FrameworkVersion>.NET Framework 4.0</FrameworkVersion>
<HelpTitle>MongoRepository documentation</HelpTitle>
<DocumentationSources>
<DocumentationSource sourceFile="..\MongoRepository\bin\Release\MongoRepository.dll" />
<DocumentationSource sourceFile="..\MongoRepository\bin\Release\MongoRepository.xml" /></DocumentationSources>
<DocumentationSource sourceFile="..\MongoRepository\bin\Release\MongoRepository.xml" />
</DocumentationSources>
<ProjectSummary>&amp;lt%3bp&amp;gt%3bThis library provides a thin abstraction layer implementing the repository pattern on top of the &amp;lt%3ba href=&amp;quot%3bhttp://nuget.org/packages/mongocsharpdriver&amp;quot%3b&amp;gt%3bOfficial MongoDB C# driver&amp;lt%3b/a&amp;gt%3b.&amp;lt%3b/p&amp;gt%3b</ProjectSummary>
<CopyrightText>&amp;#169%3b2013</CopyrightText>
<CopyrightHref>https://mongorepository.codeplex.com</CopyrightHref>
Expand All @@ -36,7 +37,15 @@
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<HelpFileVersion>1.0.0.0</HelpFileVersion>
<HelpFileVersion>1.6.0.0</HelpFileVersion>
<BuildAssemblerVerbosity>OnlyWarningsAndErrors</BuildAssemblerVerbosity>
<HelpFileFormat>HtmlHelp1</HelpFileFormat>
<IndentHtml>False</IndentHtml>
<KeepLogFile>True</KeepLogFile>
<DisableCodeBlockComponent>False</DisableCodeBlockComponent>
<CppCommentsFixup>False</CppCommentsFixup>
<CleanIntermediates>True</CleanIntermediates>
<VisibleItems>InheritedMembers, InheritedFrameworkMembers, Protected, SealedProtected</VisibleItems>
</PropertyGroup>
<!-- There are no properties for these groups. AnyCPU needs to appear in
order for Visual Studio to perform the build. The others are optional
Expand Down
8 changes: 5 additions & 3 deletions MongoRepository/trunk/MongoRepository.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>MongoRepository</id>
<version>1.5.2</version>
<version>1.6.0</version>
<authors>tgeek, RobIII</authors>
<owners>tgeek</owners>
<licenseUrl>http://mongorepository.codeplex.com/license</licenseUrl>
Expand All @@ -12,14 +12,16 @@
<tags>mongo mongodb repository</tags>
<iconUrl>http://download-codeplex.sec.s-msft.com/Download?ProjectName=mongorepository&amp;DownloadId=334950&amp;Build=19692</iconUrl>
<releaseNotes>
Updated to MongoCSharp driver 1.8.2.34, Added GetById(ObjectId id) and Delete(ObjectId id) overloads (see https://mongorepository.codeplex.com/discussions/452226)
Updated to MongoCSharp driver 1.8.3.9 (discussion 461602),
Added constructor parameters to override collectionnames (discussion 456452),
IEntity&lt;T&gt; support (discussion 454482)
</releaseNotes>
<summary>
Provides a repository pattern on top of 10gen's MongoDB C# driver.
</summary>
<language>en-US</language>
<dependencies>
<dependency id="mongocsharpdriver" version="[1.8.2,1.9.0)" />
<dependency id="mongocsharpdriver" version="[1.8.3]" />
</dependencies>
</metadata>
<files>
Expand Down
6 changes: 4 additions & 2 deletions MongoRepository/trunk/MongoRepository/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ namespace MongoRepository
/// <summary>
/// Generic Entity interface.
/// </summary>
public interface IEntity<T>
/// <typeparam name="TKey">The type used for the entity's Id.</typeparam>
public interface IEntity<TKey>
{
/// <summary>
/// Gets or sets the Id of the Entity.
/// </summary>
/// <value>Id of the Entity.</value>
[BsonId]
T Id { get; set; }
TKey Id { get; set; }
}

/// <summary>
/// "Default" Entity interface.
/// </summary>
/// <remarks>Entities are assumed to use strings for Id's.</remarks>
public interface IEntity : IEntity<string>
{
}
Expand Down
8 changes: 4 additions & 4 deletions MongoRepository/trunk/MongoRepository/MongoRepository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
<DocumentationFile>bin\Release\MongoRepository.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="MongoDB.Bson, Version=1.8.2.34, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<HintPath>..\packages\mongocsharpdriver.1.8.2\lib\net35\MongoDB.Bson.dll</HintPath>
<Reference Include="MongoDB.Bson, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver, Version=1.8.2.34, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<HintPath>..\packages\mongocsharpdriver.1.8.2\lib\net35\MongoDB.Driver.dll</HintPath>
<Reference Include="MongoDB.Driver, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7e3d1784-b1f3-4b33-a303-7facc780917e")]

[assembly: AssemblyVersion("1.5.2.0")]
[assembly: AssemblyFileVersion("1.5.2.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
35 changes: 14 additions & 21 deletions MongoRepository/trunk/MongoRepository/Repository/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
/// IRepository definition.
/// </summary>
/// <typeparam name="T">The type contained in the repository.</typeparam>
//TODO: Update documentation
public interface IRepository<T, U> : IQueryable<T>
where T : IEntity<U>
/// <typeparam name="TKey">The type used for the entity's Id.</typeparam>
public interface IRepository<T, TKey> : IQueryable<T>
where T : IEntity<TKey>
{
/// <summary>
/// Gets the Mongo collection (to perform advanced operations).
Expand All @@ -29,10 +29,9 @@ public interface IRepository<T, U> : IQueryable<T>
/// <summary>
/// Returns the T by its given id.
/// </summary>
/// <param name="id">The string representing the ObjectId of the entity to retrieve.</param>
/// <param name="id">The value representing the ObjectId of the entity to retrieve.</param>
/// <returns>The Entity T.</returns>
//TODO: Update documentation
T GetById(U id);
T GetById(TKey id);

/// <summary>
/// Adds the new entity in the repository.
Expand Down Expand Up @@ -63,9 +62,8 @@ public interface IRepository<T, U> : IQueryable<T>
/// <summary>
/// Deletes an entity from the repository by its id.
/// </summary>
/// <param name="id">The string representation of the entity's id.</param>
//TODO: Update documentation
void Delete(U id);
/// <param name="id">The entity's id.</param>
void Delete(TKey id);

/// <summary>
/// Deletes the given entity.
Expand All @@ -74,10 +72,10 @@ public interface IRepository<T, U> : IQueryable<T>
void Delete(T entity);

/// <summary>
/// Deletes the entities matching the criteria.
/// Deletes the entities matching the predicate.
/// </summary>
/// <param name="criteria">The expression.</param>
void Delete(Expression<Func<T, bool>> criteria);
/// <param name="predicate">The expression.</param>
void Delete(Expression<Func<T, bool>> predicate);

/// <summary>
/// Deletes all entities in the repository.
Expand All @@ -91,11 +89,11 @@ public interface IRepository<T, U> : IQueryable<T>
long Count();

/// <summary>
/// Checks if the entity exists for given criteria.
/// Checks if the entity exists for given predicate.
/// </summary>
/// <param name="criteria">The expression.</param>
/// <returns>True when an entity matching the criteria exists, false otherwise.</returns>
bool Exists(Expression<Func<T, bool>> criteria);
/// <param name="predicate">The expression.</param>
/// <returns>True when an entity matching the predicate exists, false otherwise.</returns>
bool Exists(Expression<Func<T, bool>> predicate);

/// <summary>
/// Lets the server know that this thread is about to begin a series of related operations that must all occur
Expand Down Expand Up @@ -128,9 +126,4 @@ public interface IRepository<T, U> : IQueryable<T>
void RequestDone();
}

//TODO: Add documentation
public interface IRepository<T> : IRepository<T, string>
where T : IEntity<string>
{
}
}
73 changes: 49 additions & 24 deletions MongoRepository/trunk/MongoRepository/Repository/MongoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
/// Deals with entities in MongoDb.
/// </summary>
/// <typeparam name="T">The type contained in the repository.</typeparam>
//TODO: Update documentation
public class MongoRepository<T, U> : IRepository<T, U>
where T : IEntity<U>
/// <typeparam name="TKey">The type used for the entity's Id.</typeparam>
public class MongoRepository<T, TKey> : IRepository<T, TKey>
where T : IEntity<TKey>
{
/// <summary>
/// MongoCollection field.
Expand All @@ -28,7 +28,7 @@ public class MongoRepository<T, U> : IRepository<T, U>
/// </summary>
/// <remarks>Default constructor defaults to "MongoServerSettings" key for connectionstring.</remarks>
public MongoRepository()
: this(Util<U>.GetDefaultConnectionString())
: this(Util<TKey>.GetDefaultConnectionString())
{
}

Expand All @@ -38,7 +38,7 @@ public MongoRepository()
/// <param name="connectionString">Connectionstring to use for connecting to MongoDB.</param>
public MongoRepository(string connectionString)
{
this.collection = Util<U>.GetCollectionFromConnectionString<T>(connectionString);
this.collection = Util<TKey>.GetCollectionFromConnectionString<T>(connectionString);
}

/// <summary>
Expand All @@ -48,7 +48,7 @@ public MongoRepository(string connectionString)
/// <param name="collectionName">The name of the collection to use.</param>
public MongoRepository(string connectionString, string collectionName)
{
this.collection = Util<U>.GetCollectionFromConnectionString<T>(connectionString, collectionName);
this.collection = Util<TKey>.GetCollectionFromConnectionString<T>(connectionString, collectionName);
}

/// <summary>
Expand All @@ -57,7 +57,7 @@ public MongoRepository(string connectionString, string collectionName)
/// <param name="url">Url to use for connecting to MongoDB.</param>
public MongoRepository(MongoUrl url)
{
this.collection = Util<U>.GetCollectionFromUrl<T>(url);
this.collection = Util<TKey>.GetCollectionFromUrl<T>(url);
}

/// <summary>
Expand All @@ -67,7 +67,7 @@ public MongoRepository(MongoUrl url)
/// <param name="collectionName">The name of the collection to use.</param>
public MongoRepository(MongoUrl url, string collectionName)
{
this.collection = Util<U>.GetCollectionFromUrl<T>(url, collectionName);
this.collection = Util<TKey>.GetCollectionFromUrl<T>(url, collectionName);
}

/// <summary>
Expand All @@ -90,10 +90,9 @@ public MongoCollection<T> Collection
/// <summary>
/// Returns the T by its given id.
/// </summary>
/// <param name="id">The string representing the ObjectId of the entity to retrieve.</param>
/// <param name="id">The Id of the entity to retrieve.</param>
/// <returns>The Entity T.</returns>
//TODO: Update documentation
public T GetById(U id)
public T GetById(TKey id)
{
if (typeof(T).IsSubclassOf(typeof(Entity)))
{
Expand Down Expand Up @@ -151,9 +150,8 @@ public void Update(IEnumerable<T> entities)
/// <summary>
/// Deletes an entity from the repository by its id.
/// </summary>
/// <param name="id">The string representation of the entity's id.</param>
//TODO: Update documentation
public void Delete(U id)
/// <param name="id">The entity's id.</param>
public void Delete(TKey id)
{
if (typeof(T).IsSubclassOf(typeof(Entity)))
{
Expand Down Expand Up @@ -184,12 +182,12 @@ public void Delete(T entity)
}

/// <summary>
/// Deletes the entities matching the criteria.
/// Deletes the entities matching the predicate.
/// </summary>
/// <param name="criteria">The expression.</param>
public void Delete(Expression<Func<T, bool>> criteria)
/// <param name="predicate">The expression.</param>
public void Delete(Expression<Func<T, bool>> predicate)
{
foreach (T entity in this.collection.AsQueryable<T>().Where(criteria))
foreach (T entity in this.collection.AsQueryable<T>().Where(predicate))
{
this.Delete(entity.Id);
}
Expand All @@ -213,13 +211,13 @@ public long Count()
}

/// <summary>
/// Checks if the entity exists for given criteria.
/// Checks if the entity exists for given predicate.
/// </summary>
/// <param name="criteria">The expression.</param>
/// <returns>True when an entity matching the criteria exists, false otherwise.</returns>
public bool Exists(Expression<Func<T, bool>> criteria)
/// <param name="predicate">The expression.</param>
/// <returns>True when an entity matching the predicate exists, false otherwise.</returns>
public bool Exists(Expression<Func<T, bool>> predicate)
{
return this.collection.AsQueryable<T>().Any(criteria);
return this.collection.AsQueryable<T>().Any(predicate);
}

/// <summary>
Expand Down Expand Up @@ -312,22 +310,49 @@ public IQueryProvider Provider
#endregion
}

//TODO: Update documentation
/// <summary>
/// Deals with entities in MongoDb.
/// </summary>
/// <typeparam name="T">The type contained in the repository.</typeparam>
/// <remarks>Entities are assumed to use strings for Id's.</remarks>
public class MongoRepository<T> : MongoRepository<T, string>, IRepository<T, string>
where T : IEntity<string>
{
/// <summary>
/// Initializes a new instance of the MongoRepository class.
/// Uses the Default App/Web.Config connectionstrings to fetch the connectionString and Database name.
/// </summary>
/// <remarks>Default constructor defaults to "MongoServerSettings" key for connectionstring.</remarks>
public MongoRepository()
: base() { }

/// <summary>
/// Initializes a new instance of the MongoRepository class.
/// </summary>
/// <param name="url">Url to use for connecting to MongoDB.</param>
public MongoRepository(MongoUrl url)
: base(url) { }

/// <summary>
/// Initializes a new instance of the MongoRepository class.
/// </summary>
/// <param name="url">Url to use for connecting to MongoDB.</param>
/// <param name="collectionName">The name of the collection to use.</param>
public MongoRepository(MongoUrl url, string collectionName)
: base(url, collectionName) { }

/// <summary>
/// Initializes a new instance of the MongoRepository class.
/// </summary>
/// <param name="connectionString">Connectionstring to use for connecting to MongoDB.</param>
public MongoRepository(string connectionString)
: base(connectionString) { }

/// <summary>
/// Initializes a new instance of the MongoRepository class.
/// </summary>
/// <param name="connectionString">Connectionstring to use for connecting to MongoDB.</param>
/// <param name="collectionName">The name of the collection to use.</param>
public MongoRepository(string connectionString, string collectionName)
: base(connectionString, collectionName) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
/// IRepositoryManager definition.
/// </summary>
/// <typeparam name="T">The type contained in the repository to manage.</typeparam>
//TODO: Update documentation
public interface IRepositoryManager<T, U>
where T : IEntity<U>
/// <typeparam name="TKey">The type used for the entity's Id.</typeparam>
public interface IRepositoryManager<T, TKey>
where T : IEntity<TKey>
{
/// <summary>
/// Gets a value indicating whether the collection already exists.
Expand Down Expand Up @@ -159,9 +159,4 @@ public interface IRepositoryManager<T, U>
GetIndexesResult GetIndexes();
}

//TODO: Update documentation
public interface IRepositoryManager<T> : IRepositoryManager<T, string>
where T : IEntity<string>
{
}
}
Loading

0 comments on commit ccb128a

Please sign in to comment.