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()
时间: 2024-04-05 08:29:07 浏览: 259
这段错误信息表明LINQ查询表达式无法被翻译,其中的int.Parse方法无法被转换。出现这种情况通常是因为EF Core无法将这个方法转换成SQL语句中的等效操作。可以尝试重写查询表达式,使其可以被翻译,或者明确地插入一个AsEnumerable、AsAsyncEnumerable、ToList或ToListAsync方法,将查询转换为客户端评估。你可以参考微软官方文档中的相关信息链接进行更深入的了解和操作。
相关问题
System.InvalidOperationException:“The entity type 'C_ProjectSearch' requires a primary key to be defined.”
这个错误通常是因为实体类型没有定义主键引起的。在EF Core中,每个实体都必须有一个主键,否则就会出现该异常。所以你需要在你的实体类中定义一个主键。你可以使用 [Key] 特性或者在 OnModelCreating 方法中使用 modelBuilder.Entity<T>().HasKey() 方法来定义主键。例如:
```
public class C_ProjectSearch
{
[Key]
public int Id { get; set; }
//其他属性
}
```
System.InvalidOperationException:“线程间操作无效: 从不是创建控件“lb_test_state”的线程访问它。”
这个错误通常是因为在不同的线程中访问了同一个控件,而 Windows 窗体只允许在创建控件的线程中访问控件。解决方法是使用 Invoke 或者 BeginInvoke 方法将访问控件的代码放入创建控件的线程中执行。例如:
```
if (lb_test_state.InvokeRequired)
{
lb_test_state.Invoke((MethodInvoker)delegate
{
// 访问 lb_test_state 控件的代码
});
}
else
{
// 访问 lb_test_state 控件的代码
}
```
这样就可以避免线程间操作无效的错误了。
阅读全文