Skip to content

Instantly share code, notes, and snippets.

Avatar

Maarten Merken merken

View GitHub Profile
@merken
merken / MyDbContext.cs
Last active Aug 18, 2017
Entity Framework Core: Data type 'nvarchar' is not supported in this form. Either specify the length explicitly in the type name, for example as 'nvarchar(16)', or remove the data type and use APIs such as HasMaxLength to allow EF choose the data type.
View MyDbContext.cs
public class MyDbContext : MyContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<MyEntity>(entity =>
{
entity.Property(e => e.MyProperty)
.HasColumnType("nvarchar(4000)");
@merken
merken / project.csproj
Created Aug 18, 2017
ef core references
View project.csproj
<Project Sdk=”Microsoft.NET.Sdk”>
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include=”Microsoft.EntityFrameworkCore.Design” Version=”2.0.0" />
<PackageReference Include=”Microsoft.EntityFrameworkCore.SqlServer” Version=”2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include=”Microsoft.EntityFrameworkCore.Tools.DotNet” Version=”2.0.0" />
@merken
merken / UnitTest1.cs
Created Aug 18, 2017
Simple unit test
View UnitTest1.cs
public class UnitTest1
{
[Fact]
public void Test1()
{
Assert.Equal(1, 1);
}
}
@merken
merken / Dockerfile
Last active Aug 24, 2017
Dockerfile Merken.NetCoreBuild.App
View Dockerfile
FROM microsoft/aspnetcore
# set up network
ENV ASPNETCORE_URLS http://+:5000
WORKDIR /app
EXPOSE 5000
COPY . /app
ENTRYPOINT ["dotnet", "netcoreapp.dll"]
@merken
merken / Dockerfile
Last active Sep 22, 2017
Dockerfile for jenkins with netcore runtime
View Dockerfile
# this is the jenkins version, to upgrade the base image, alter the argument below
ARG JENKINS_VERSION=2.60.2
FROM jenkins:$JENKINS_VERSION
LABEL name "netcorebuild"
MAINTAINER Maarten Merken
ARG NET_CORE_APP_NAME=netcoreapp
ARG JENKINS_CLI_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/cli/$JENKINS_VERSION/cli-$JENKINS_VERSION-jar-with-dependencies.jar
# get rid of admin password setup
ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false"
View netcoreapp.xml
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@2.11">
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers>
<hudson.triggers.SCMTrigger>
<spec>* * * * *</spec>
View IInvoicingService.cs
public interface IInvoicingService
{
string CreateInvoice(float numberOfHoursPerformed);
}
View InvoicingServices.cs
public class EuroInvoicingService : IInvoicingService
{
private float rate = 25;
private string currency = "EUR";
private float vat = 0.21f;
public string CreateInvoice(float numberOfHoursPerformed)
{
var value = rate * numberOfHoursPerformed;
value += value * vat;
View Startup.MultiRegister.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
View InvoicesController.cs
[Route("api/[controller]")]
[ApiController]
public class InvoicesController : ControllerBase
{
private readonly IEnumerable<IInvoicingService> invoicingServices;
public InvoicesController(IEnumerable<IInvoicingService> invoicingServices)
{
this.invoicingServices = invoicingServices;
}