AspNetCore.IQueryable.Extensions 使用教程

AspNetCore.IQueryable.Extensions 使用教程

AspNetCore.IQueryable.ExtensionsLINQ extensions to help build IQueryAble Expressions项目地址:https://gitcode.com/gh_mirrors/as/AspNetCore.IQueryable.Extensions

1. 项目的目录结构及介绍

AspNetCore.IQueryable.Extensions 是一个用于简化 LINQ 查询表达式构建的开源项目。以下是该项目的目录结构及其介绍:

AspNetCore.IQueryable.Extensions/
├── src/
│   ├── AspNetCore.IQueryable.Extensions/
│   │   ├── Extensions/
│   │   │   ├── IQueryableExtensions.cs
│   │   │   └── QueryableExtensions.cs
│   │   ├── Filters/
│   │   │   ├── QueryFilterAttribute.cs
│   │   │   └── QueryOperatorAttribute.cs
│   │   ├── Models/
│   │   │   ├── QueryCriteria.cs
│   │   │   └── QueryOptions.cs
│   │   ├── Program.cs
│   │   ├── Startup.cs
│   │   └── AspNetCore.IQueryable.Extensions.csproj
│   └── AspNetCore.IQueryable.Extensions.Tests/
│       ├── QueryableExtensionsTests.cs
│       └── AspNetCore.IQueryable.Extensions.Tests.csproj
├── .gitignore
├── LICENSE
├── README.md
└── AspNetCore.IQueryable.Extensions.sln

目录结构说明

  • src/AspNetCore.IQueryable.Extensions/: 项目的主要源代码目录。
    • Extensions/: 包含扩展方法的文件。
    • Filters/: 包含查询过滤器相关的文件。
    • Models/: 包含查询模型相关的文件。
    • Program.cs: 项目的入口文件。
    • Startup.cs: 项目的启动配置文件。
    • AspNetCore.IQueryable.Extensions.csproj: 项目文件。
  • src/AspNetCore.IQueryable.Extensions.Tests/: 项目的测试代码目录。
  • .gitignore: Git 忽略文件。
  • LICENSE: 项目许可证文件。
  • README.md: 项目说明文档。
  • AspNetCore.IQueryable.Extensions.sln: 解决方案文件。

2. 项目的启动文件介绍

项目的启动文件是 Program.cs,它包含了应用程序的入口点。以下是 Program.cs 的示例代码:

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace AspNetCore.IQueryable.Extensions
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}

启动文件说明

  • Main 方法是应用程序的入口点,负责创建和运行主机。
  • CreateHostBuilder 方法配置并创建主机,使用 Startup 类进行进一步的配置。

3. 项目的配置文件介绍

项目的配置文件是 Startup.cs,它包含了应用程序的配置和服务的注册。以下是 Startup.cs 的示例代码:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace AspNetCore.IQueryable.Extensions
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddSwaggerGen();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

配置

AspNetCore.IQueryable.ExtensionsLINQ extensions to help build IQueryAble Expressions项目地址:https://gitcode.com/gh_mirrors/as/AspNetCore.IQueryable.Extensions

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
System.InvalidOperationException: The LINQ expression 'DbSet<z_tjdj_yydj>() .Where(z => z.YYBH.Substring( startIndex: 0, length: z.YYBH.Length - 6) == __Substring_0) .Max(z => int.Parse(z.YYBH.Substring( startIndex: 10, length: 5)))' could not be translated. Additional information: Translation of method 'int.Parse' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information. at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.<VisitMethodCall>g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0& ) at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.Max[TSource,TResult](IQueryable`1 source, Expression`1 selector) at VOL.TJYY.Services.z_tjdj_yydjService.<>c__DisplayClass10_0.<Import1>b__0(List`1 list) at VOL.Core.BaseProvider.ServiceBase`2.Import(List`1 files) in D:\work\TJYYHT_VOL\Net6版本\VOL.Core\BaseProvider\ServiceBase.cs:line 459 at VOL.TJYY.Services.z_tjdj_yydjService.Import(List`1 files) at VOL.TJYY.Services.z_tjdj_yydjService.Import1(List`1 fileInput, Dictionary`2 data) at VOL.TJYY.Controllers.z_tjdj_yydjController.Import1(List`1 fileInput, Dictionary`2 data) at lambda_method901(Closure , Object , Object[] ) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伍霜盼Ellen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值