Created
July 4, 2013 09:24
-
-
Save eka808/5926225 to your computer and use it in GitHub Desktop.
Make the Set entity framework method usable in unit tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Overload of the Set method of entity framework | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <returns></returns> | |
public IDbSet<T> Set<T>() where T : class | |
{ | |
var correspondingDbSets = this.GetType().GetProperties().Where(a => a.PropertyType == typeof(IDbSet<T>)); | |
if (correspondingDbSets.Count() == 1) | |
{ | |
var correspondingProperty = correspondingDbSets.FirstOrDefault(); | |
return (IDbSet<T>)correspondingProperty.GetValue(this,null); | |
} | |
throw new Exception("Unexisting dbset"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment