您现在的位置是: 首页 >  .NET开发 >  文章详情 文章详情

EntityFrameworkCore中linq转sql

2019-08-19 【.NET开发】 2545人浏览

  1. public class IQueryableExtensions  

  2. {

  3.    private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo();

  4.    private static readonly FieldInfo QueryCompilerField = typeof(EntityQueryProvider).GetTypeInfo().DeclaredFields.First(x => x.Name == "_queryCompiler");

  5.    private static readonly PropertyInfo NodeTypeProviderField = QueryCompilerTypeInfo.DeclaredProperties.Single(x => x.Name == "NodeTypeProvider");

  6.    private static readonly MethodInfo CreateQueryParserMethod = QueryCompilerTypeInfo.DeclaredMethods.First(x => x.Name == "CreateQueryParser");

  7.    private static readonly FieldInfo DataBaseField = QueryCompilerTypeInfo.DeclaredFields.Single(x => x.Name == "_database");

  8.    private static readonly FieldInfo QueryCompilationContextFactoryField = typeof(Database).GetTypeInfo().DeclaredFields.Single(x => x.Name == "_queryCompilationContextFactory");

  9.    public static string ToSqlTEntity>(this IQueryableTEntity> query) where TEntity : class

  10.    {

  11.        if (!(query is EntityQueryableTEntity>) && !(query is InternalDbSetTEntity>))

  12.        {

  13.            throw new ArgumentException("Invalid query");