EntityFrameworkCore中linq转sql

  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");

上一篇: C#利用反射来判断对象是否包含某个属性的实现方法
下一篇: .NET实现WebSocket服务端即时通信实例