Answers for "idbset sqlquery"

C#
0

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();
        }
    }
}
Posted by: Guest on March-24-2020

C# Answers by Framework

Browse Popular Code Answers by Language