idbset sqlquery code example
Example: idbset sqlquery
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();
}
}
}