using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using System.Linq.Dynamic.Core;

namespace IRaCIS.Core.Infrastructure.Extention
{
    public static class IQueryableExtensions
    {
       /// <summary>
       /// 获取第一条 为null提示
       /// </summary>
       /// <typeparam name="TSource"></typeparam>
       /// <param name="source"></param>
       /// <returns></returns>
       /// <exception cref="QueryBusinessObjectNotExistException"></exception>
        public  static async Task<TSource> FirstNotNullAsync<TSource>(this IQueryable<TSource> source)
        {
            var result =await source.FirstOrDefaultAsync();

            if (result == null)
            {
                throw new QueryBusinessObjectNotExistException($"The query object does not exist in database, Please check the query parameters");
            }
            else
            {
                return result;
            }
        }


    }
}