Skip to content

Instantly share code, notes, and snippets.

View af4jm's full-sized avatar

John Meyer af4jm

View GitHub Profile
@haacked
haacked / ModelBuilderExtensions.cs
Last active March 29, 2024 14:16
Example of applying an EF Core global query filter on all entity types that implement an interface
/*
Copyright Phil Haack
Licensed under the MIT license - https://github.com/haacked/CodeHaacks/blob/main/LICENSE.
*/
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
CREATE DATABASE [٠০౦০٠];
GO
USE [٠০౦০٠];
GO
CREATE SCHEMA [٠০౦০٠];
GO
CREATE TABLE [٠০౦০٠].[٠০౦০٠]([٠০౦০٠] NVARCHAR(20), [۰০౦০٠] NVARCHAR(20), [٠০౦০۰] NVARCHAR(20), [۰০౦০۰] NVARCHAR(20));
GO
CREATE UNIQUE CLUSTERED INDEX [٠০౦০٠] ON [٠০౦০٠].[٠০౦০٠]([٠০౦০٠], [۰০౦০٠], [٠০౦০۰], [۰০౦০۰]);
GO
using System;
using System.Text.RegularExpressions;
using System.Reflection;
namespace RegexLibraryBuilder
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class RegexBuilderMain
{
@haacked
haacked / ToDictionaryBetter.cs
Last active December 18, 2015 13:49
An implementation of ToDictionary that provides information about which key had duplicate entries.
public static class EnumerableExtensions
{
public static Dictionary<TKey, TSource> ToDictionaryBetter<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
return source.GroupBy(keySelector).ToDictionary(group => group.Key, group =>
{
try
{
return group.Single();
}