fenish
fenish
Explore posts from servers
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
I'll try thanks
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
thanks
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
I'll try
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
okey
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
ah you mean rgis
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
application dir
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
specify migration project to "application" not data
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
it still gives error about something like
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
when i run from application
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
i want my migrations to inside of Data
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[WebApiTemplate.Data.Sql.DatabaseContext]' while attempting to activate 'WebApiTemplate.Data.Sql.DatabaseContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time,
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[WebApiTemplate.Data.Sql.DatabaseContext]' while attempting to activate 'WebApiTemplate.Data.Sql.DatabaseContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time,
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
No description
24 replies
CC#
Created by fenish on 10/16/2023 in #help
❔ Ef core multiple projects
using Microsoft.EntityFrameworkCore;
using WebApiTemplate.Data.Entities;

namespace WebApiTemplate.Data.Sql;

public class DatabaseContext : DbContext
{
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
{
}
public required DbSet<Books> Books { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured) return;
var host = Environment.GetEnvironmentVariable("DB_HOST");
var port = Environment.GetEnvironmentVariable("DB_PORT");
var user = Environment.GetEnvironmentVariable("DB_USER");
var password = Environment.GetEnvironmentVariable("DB_PASSWORD");
var database = Environment.GetEnvironmentVariable("DB_DATABASE");

var connectionString = $"Host={host};Port={port};Username={user};Password={password};Database={database}";
optionsBuilder.UseNpgsql(connectionString);
}
}
using Microsoft.EntityFrameworkCore;
using WebApiTemplate.Data.Entities;

namespace WebApiTemplate.Data.Sql;

public class DatabaseContext : DbContext
{
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
{
}
public required DbSet<Books> Books { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured) return;
var host = Environment.GetEnvironmentVariable("DB_HOST");
var port = Environment.GetEnvironmentVariable("DB_PORT");
var user = Environment.GetEnvironmentVariable("DB_USER");
var password = Environment.GetEnvironmentVariable("DB_PASSWORD");
var database = Environment.GetEnvironmentVariable("DB_DATABASE");

var connectionString = $"Host={host};Port={port};Username={user};Password={password};Database={database}";
optionsBuilder.UseNpgsql(connectionString);
}
}
24 replies