Last active
August 29, 2015 14:23
-
-
Save njmube/eef63ebf036e43033b18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Data.Entity; | |
namespace DAL.Models | |
{ | |
public static class IDbSetExtensions | |
{ | |
/// <summary> | |
/// When using IDbSet Interface the SQLQuery method is hidden this extension method will allow us to expose the method | |
/// </summary> | |
/// <typeparam name="TEntity">Entity Class</typeparam> | |
/// <param name="set">IDbSet</param> | |
/// <param name="query">String sql query</param> | |
/// <returns></returns> | |
public static IEnumerable<TEntity> SearchQuery<TEntity>(this IDbSet<TEntity> set, string query) | |
where TEntity : class | |
{ | |
var dbSet = set as DbSet<TEntity>; | |
if (dbSet != null) | |
{ | |
return dbSet.SqlQuery(query); | |
} | |
throw new NotSupportedException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment