Skip to content
This repository was archived by the owner on Feb 22, 2020. It is now read-only.

Commit 22f0905

Browse files
committed
* Added GetById(ObjectId id) overload
1 parent 9917911 commit 22f0905

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

MongoRepository/dev/MongoRepository/Repository/MongoRepository.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ public MongoRepository(MongoUrl url, string collectionName)
8181
/// <value>The Mongo collection (to perform advanced operations).</value>
8282
public MongoCollection<T> Collection
8383
{
84-
get
85-
{
86-
return this.collection;
87-
}
84+
get { return this.collection; }
8885
}
8986

9087
/// <summary>
@@ -96,12 +93,22 @@ public virtual T GetById(TKey id)
9693
{
9794
if (typeof(T).IsSubclassOf(typeof(Entity)))
9895
{
99-
return this.collection.FindOneByIdAs<T>(new ObjectId(id as string));
96+
return this.GetById(new ObjectId(id as string));
10097
}
10198

10299
return this.collection.FindOneByIdAs<T>(BsonValue.Create(id));
103100
}
104101

102+
/// <summary>
103+
/// Returns the T by its given id.
104+
/// </summary>
105+
/// <param name="id">The Id of the entity to retrieve.</param>
106+
/// <returns>The Entity T.</returns>
107+
public virtual T GetById(ObjectId id)
108+
{
109+
return this.collection.FindOneByIdAs<T>(id);
110+
}
111+
105112
/// <summary>
106113
/// Adds the new entity in the repository.
107114
/// </summary>

0 commit comments

Comments
 (0)