🗃️ created dbcontext
Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
		
							parent
							
								
									cc7bb34302
								
							
						
					
					
						commit
						f925b87883
					
				
					 3 changed files with 22 additions and 1 deletions
				
			
		
							
								
								
									
										11
									
								
								backend/Context/DbContext.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								backend/Context/DbContext.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| using backend; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| 
 | ||||
| public class MovieDbContext: DbContext | ||||
| { | ||||
|     public MovieDbContext(DbContextOptions<MovieDbContext> options) : base(options) | ||||
|     { | ||||
|     } | ||||
| 
 | ||||
|     public DbSet<Movie> Movies { get; set; } | ||||
| } | ||||
|  | @ -1,3 +1,5 @@ | |||
| using Microsoft.EntityFrameworkCore; | ||||
| 
 | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
| 
 | ||||
| // Add services to the container. | ||||
|  | @ -7,6 +9,11 @@ builder.Services.AddControllers(); | |||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwaggerGen(); | ||||
| 
 | ||||
| var configuration = builder.Configuration;  | ||||
| 
 | ||||
| builder.Services.AddDbContext<MovieDbContext>(options => | ||||
|     options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"))); | ||||
| 
 | ||||
| var app = builder.Build(); | ||||
| 
 | ||||
| // Configure the HTTP request pipeline. | ||||
|  |  | |||
|  | @ -5,5 +5,8 @@ | |||
|       "Microsoft.AspNetCore": "Warning" | ||||
|     } | ||||
|   }, | ||||
|   "AllowedHosts": "*" | ||||
|   "AllowedHosts": "*", | ||||
|   "ConnectionStrings": { | ||||
|     "DefaultConnection": "Server=localhost;Database=movie-database;Port=5432;;Username=postgres;Password=moviedatabase" | ||||
|   } | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 haraldnilsen
						haraldnilsen