Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wrote a C# project with the change that I used migration

To be able to use sturtup in the program:

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

, and commands in Startup:

public class Startup
{
    public IConfiguration Configuration { get; set; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }
}


public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<readscalecontext>(options =>
    {
        options.UseSqlServer(Configuration.GetConnectionString("ReadScaleConnection"));
    });
}

The tables were all created correctly with the migration command. I just want to know why the tables are not called and it returns null. The example of my first command is:

List<accounttype> GetAllAccountType();
and used this:
 dgvOperators.DataSource = _operatorService.GetAllOperatore();

Thank you very much for your guidance

Error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

db was null.

What I have tried:

i use enabale-migration and update-database
Posted
Updated 28-Oct-22 22:20pm

1 solution

Look at the error message:
System.NullReferenceException: 'Object reference not set to an instance of an object.'

So you need to use the debugger to stop at the line that throws the exception and examine which variable is null and why.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900