Skip to content

Instantly share code, notes, and snippets.

[HttpGet]
public async Task<ActionResult<IEnumerable<Blog>>> GetBlogs()
{
var connection = _context.Database.GetDbConnection();
var data = await connection.QueryAsync<Blog>("SELECT * FROM Blogs");
return data.ToList();
}
@fugaku
fugaku / BlogsController.cs
Created February 16, 2019 10:44
EF Core Getting Started
public class BlogsController : ControllerBase
{
private readonly AppContext _context;
public BlogsController(AppContext context)
{
_context = context;
}
// GET: api/Blogs
@fugaku
fugaku / Startup.cs
Created February 16, 2019 02:18
EF Core Getting Started
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
var connection = "Server=localhost;Port=5432;Database=Test;User Id=postgres;Password=postgres;";
@fugaku
fugaku / AppContext.cs
Created February 16, 2019 02:01
EF Core Getting Started
public class AppContext : DbContext
{
public AppContext(DbContextOptions<AppContext> options)
: base(options)
{ }
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}
@fugaku
fugaku / Post.cs
Created February 16, 2019 01:57
EF Core Getting Started
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
@fugaku
fugaku / Blog.cs
Last active February 16, 2019 01:56
EF Core Getting Started
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public ICollection<Post> Posts { get; set; }
}
@fugaku
fugaku / OdbcRepository.cs
Created November 29, 2018 15:11
ODBC Connection
public class OdbcRepository
{
public List<Model> Get(string name)
{
//Create a connection
var connection = new OdbcConnection(connectionString);
//Construct the query
//Usually you use @parameter as the syntax for querying SQL Server
//But for querying to Microsoft Access you must use ?
server {
listen 80;
listen [::]:80;
. . .
root /var/www/laravel/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
@fugaku
fugaku / myaspnetcore.service
Last active October 6, 2018 23:26
systemd aspnetcore service
[Unit]
Description=My ASP.NET Core
[Service]
WorkingDirectory=/var/www/myaspnetcore
ExecStart=/usr/bin/dotnet /var/www/myaspnetcore/myaspnetcore.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
@fugaku
fugaku / nginx-sites-available-default
Last active October 6, 2018 13:38
nginx setup aspnetcore
server {
listen 80;
root /var/www/myaspnetcore/wwwroot;
server_name _;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;