I am working a new .net core Razor Page application using Visual Studio 2022 with framework 7.0 which accesses to DB2 to get data so I installed following packages from NuGet
<ItemGroup>
<PackageReference Include="IBM.Data.DB2.Core" Version="3.1.0.600" />
<PackageReference Include="IBM.EntityFrameworkCore" Version="7.0.0.200" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.5.23280.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.5.23280.1" />
</ItemGroup>
I registered DBContext in program.cs with the connection sting defined in appsettings.json as "CDWContext": "UID=XXXX;PWD=XXXX;dcdw12p;DSN=PDOAA;DBALIAS=PDOAA;" which I used in console app and works fine.
builder.Services.AddDbContext<MyCDWContext>(options =>
{
options.UseDb2(builder.Configuration.GetConnectionString("CDWContext"), si =>
si.SetServerInfo(IBMDBServerType.AS400, IBMDBServerVersion.AS400_07_02));
});
And
public class MyCDWContext : DbContext
{
public MyCDWContext(DbContextOptions<MyCDWContext> options)
: base(options)
{ }
public DbSet<People> People { get; } = default!;
}
When calling public void OnGet()
{
this.People = (from p in _context.People where p.hireDate == "02/18/2018" select p).ToList();
}
I got following error:
· ArgumentNullException: Value cannot be null. (Parameter 'source')
o System.ArgumentNullException.Throw(string paramName)
o System.ArgumentNullException.ThrowIfNull(object argument, string paramName)
o System.Linq.Queryable.Where<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
o SRMForm.Pages.ListStopFriskModel.OnGet() in ListStopFrisk.cshtml.cs
+
20. this.People = (from p in _context.People where p.hireDate == "02/18/2018" select p).ToList();
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+VoidHandlerMethod.Execute(object receiver, object[] arguments)
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
o Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
o Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
o Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
o Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Can someone give me ideal to solve the issue? Thanks in advance!
------------------------------
baixiong zhao
------------------------------