Skip to content

Instantly share code, notes, and snippets.

View divega's full-sized avatar
💭
Drinking from a firehose

Diego Vega divega

💭
Drinking from a firehose
View GitHub Profile
@divega
divega / MyContext.cs
Last active May 18, 2020 04:35
Simple builder class for creating TVPs that work in .NET Core 1.0
using Microsoft.EntityFrameworkCore;
namespace TvpSampleApp
{
public class MyContext : DbContext
{
public DbSet<Person> People { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@divega
divega / ef6.2-issue275.cs
Last active May 23, 2017 00:22
Pattern to enable cached code first models in EF 6.2
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
namespace MyApplication
{
public class MyDbConfiguration : DbConfiguration
{
public MyDbConfiguration() : base()
{
this.SetModelStore(new DefaultDbModelStore(Directory.GetCurrentDirectory()));
@divega
divega / ef6.2-issue274.cs
Last active May 23, 2017 00:21
Pattern for configuring indexes in EF6.2
using System;
using System.Data.Entity;
namespace MyApplication
public class MyContext: DbContext
{
public DbSet<Person> People { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
@divega
divega / ef6.2-issue241.cs
Last active May 23, 2017 00:20
Pattern for using Like in LINQ in EF 6.2
var query = db.People.Where(p => DbFunctions.Like(p.Name, "w%"));
@divega
divega / ef6.2-issue165.cs
Last active February 11, 2019 19:10
Pattern to enable sequences in EF 6.2
System.Data.Entity.SqlServer.SqlProviderServices.UseScopeIdentity = false;
@divega
divega / EntityAndQuery.Program.cs
Created July 26, 2018 20:17
Mapping the same table to two objects
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace ConsoleApp33
{
class Program
{
static void Main(string[] args)
{
using (var context = new MyContext())
@divega
divega / Program.cs
Created May 31, 2019 18:06
Using a shared in-memory SQLite database in a test
using System;
using System.Linq;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace EnsureCreatedSqliteInMemory
{
class Program
{
@divega
divega / SortWithJoin.cs
Created November 7, 2019 08:24
Sorting an array with the order of another array using LINQ's Join
using System;
using System.Linq;
namespace SortWithJoin
{
class Program
{
static void Main(string[] args)
{
var keys = new [] { 5, 7, 3, 2, 1, 4, 6, 9, 8 };
@divega
divega / Program.cs
Last active May 21, 2022 01:04
Playing with recent and upcoming features from C# 8.0 through 11.0
// What's new in C#
// Good places to start:
// - https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-version-history#c-version-72
// - https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-11
#region implicit and global usings (C# 10)
global using Microsoft.EntityFrameworkCore;
global using System.Collections;
using System;
#endregion