Skip to content

Instantly share code, notes, and snippets.

Felipe Gavilán gavilanch

  • República Dominicana
View GitHub Profile
View script-2012.sql
USE [master]
GO
/****** Object: Database [ValuesDB] Script Date: 16-Jul-20 10:45:22 PM ******/
CREATE DATABASE [ValuesDB]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'ValuesDB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\ValuesDB.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
LOG ON
( NAME = N'ValuesDB_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\ValuesDB_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
GO
View PeliculasController.cs
peliculasQueryable = peliculasQueryable.OrderByDescending(x => x.VotosPelicula.Average(y => y.Voto));
View Startup.cs
services.AddDbContext<ApplicationDbContext>((serviceProvider, dbContextBuilder) =>
{
var connectionStringPlaceHolder = Configuration.GetConnectionString("PlaceHolderConnection");
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
var dbName = httpContextAccessor.HttpContext.Request.Headers["tenantId"].First();
var connectionString = connectionStringPlaceHolder.Replace("{dbName}", dbName);
dbContextBuilder.UseSqlServer(connectionString);
});
View appsettings.json
"ConnectionStrings": {
"PlaceHolderConnection": "Data Source=.;Initial Catalog={dbName};Integrated Security=True",
}
...
View startup.cs
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")
));
View PeopleController.cs
[HttpGet("{id}")]
public async Task<ActionResult<Person>> Get(int id)
{
var person = await context.People.Include(x => x.MoviesActors).ThenInclude(x => x.Movie).FirstOrDefaultAsync(x => x.Id == id);
if (person == null) { return NotFound(); }
return person;
}
View countries.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
View Startup.cs
// Unnecessary code removed for brevity
namespace WebApiSwaggerVersion
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(config =>
View Controllers.cs
// Version 1
namespace WebApiSwaggerVersion.Controllers.V1
{
[ApiController]
[Route("api/v1/[controller]")]
public class WeatherForecastController : ControllerBase
{...}
}
View Startup.cs
services.AddControllers(options =>
{
options.Conventions.Add(new GroupingByNamespaceConvention());
});
You can’t perform that action at this time.