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 / MyDbContext.cs
Last active Mar 8, 2021
Providing a connection string in EF core
View MyDbContext.cs
public class MyDbContext : MyContext
{
private readonly string connectionString;
public MyDbContext(string connectionString) : base()
{
this.connectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@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>
@merken
merken / Jenkinsfile
Last active Dec 3, 2018
netCoreBuild Jenkinsfile
View Jenkinsfile
import groovy.json.JsonSlurper
VERSION_NUMBER = ""
/** Pipeline **/
node {
ws('netcore') {
try{
stage("scm pull") {
deleteDir();
@merken
merken / Jenkinsfile
Last active Dec 3, 2018
basic Jenkinsfile
View Jenkinsfile
//GLOBAL VARIABLE
VERSION_NUMBER = ""
/** Pipeline **/
node {
ws('myapp') {
try{
stage("scm pull") {
cloneRepo();
VERSION_NUMBER = "1.2.3"
currentBuild.displayName = "$VERSION_NUMBER";
View UnitOfWorkFilter.cs
using System;
using System.Data;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;
namespace txn
{
public class UnitOfWorkFilter : IAsyncActionFilter
{
private readonly IDbTransaction transaction;