Skip to content

Instantly share code, notes, and snippets.

Avatar

Rowan Miller rowanmiller

View GitHub Profile
@rowanmiller
rowanmiller / UrlRedirectTracer.cs
Last active Jun 11, 2019
Trace the chain of redirects for a set of URLs
View UrlRedirectTracer.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Xml.Linq;
namespace RedirectTracer
{
class Program
View Temp_SampleCode.cs
var names = new List<String>
{
"Ana",
"Felipe",
"Emillia"
};
names.ForEach(name =>
Console.WriteLine($"Hello {name}"));
@rowanmiller
rowanmiller / Lab1.cs
Last active Apr 20, 2017
Sample Code
View Lab1.cs
using System;
namespace ConsoleApplication2
{
public class Program
{
public static void Main()
{
int mark = 66;
@rowanmiller
rowanmiller / Demo.cs
Last active Jul 19, 2016
EF Core | Custom Model Validation Rules
View Demo.cs
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
@rowanmiller
rowanmiller / Demo.cs
Last active Feb 29, 2016
EF6.x | Same context instance to different databases
View Demo.cs
using System;
using System.Data.Entity;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
private static string connection_one = "Server=(localdb)\\mssqllocaldb;Database=Blogging_One;Trusted_Connection=True;";
private static string connection_two = "Server=(localdb)\\mssqllocaldb;Database=BLogging_Two;Trusted_Connection=True;";
@rowanmiller
rowanmiller / Demo.cs
Created Feb 11, 2016
EF7 | Use DbSet property names as table names
View Demo.cs
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var dbSets = GetType().GetProperties()
.Where(p => p.PropertyType.Name == "DbSet`1")
.Select(p => new
{
PropertyName = p.Name,
EntityType = p.PropertyType.GenericTypeArguments.Single()
})
.ToArray();
@rowanmiller
rowanmiller / Demo.cs
Last active Nov 5, 2019
EF6.x | Correlating SQL to code
View Demo.cs
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure.Interception;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Demo
@rowanmiller
rowanmiller / Demo.cs
Last active Aug 27, 2017
EF7 | Pluralizing table names
View Demo.cs
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
modelBuilder.Entity(entity.Name).ToTable(entity.Name + "s");
}
}