Skip to content

Instantly share code, notes, and snippets.

View karenpayneoregon's full-sized avatar
🎯
Focusing

Karen Payne karenpayneoregon

🎯
Focusing
View GitHub Profile
@karenpayneoregon
karenpayneoregon / DbContextExtensions.cs
Last active February 16, 2026 02:32
Detect EF Core model has a query filter (HasQueryFilter)
using Microsoft.EntityFrameworkCore;
public static class DbContextExtensions
{
/// <summary>
/// Determines whether the specified entity type has a query filter applied in the current <see cref="DbContext"/>.
/// </summary>
/// <typeparam name="TEntity">The type of the entity to check for a query filter.</typeparam>
/// <param name="context">The <see cref="DbContext"/> instance to inspect.</param>
@karenpayneoregon
karenpayneoregon / QueryExtensions.cs
Created February 10, 2026 22:36
EF Core extension to assist with debugging during development phase of a project
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore;
namespace TODO.Classes.Extensions;
/// <summary>
/// Provides extension methods for enhancing and debugging Entity Framework Core queries.
/// </summary>
public static class QueryExtensions
{
using Microsoft.EntityFrameworkCore;
namespace NorthWindSqlLiteApp1.Classes.Extensions; // Change to match your project namespace
public static class EntityExtensions
{
/// <summary>
/// Retrieves a list of CLR types representing the entities defined in the model of the specified <see cref="DbContext"/>.
/// </summary>
/// <param name="context">
/// The <see cref="DbContext"/> instance from which to retrieve the entity types.
@karenpayneoregon
karenpayneoregon / FileHelpers.cs
Created January 30, 2026 03:51
Determines if path is a file or folder
public class FileHelpers
{
public static (bool isFolder, bool success) IsFileOrFolder(string path)
{
try
{
var attr = File.GetAttributes(path);
return attr.HasFlag(FileAttributes.Directory) ? (true, true)! : (false, true)!;
}
catch (FileNotFoundException)
@karenpayneoregon
karenpayneoregon / LogicalPatterns.cs
Created January 21, 2026 18:59
Logical patterns
public static class LogicalPatterns
{
public static string ClassifyTemperature(this double temp) => temp switch
{
< 0 => "Bitterly cold",
>= 0 and < 20 => "Chilly",
>= 20 and < 30 => "Comfortably warm",
>= 30 and not 100 => "Uncomfortably hot",
100 => "At the boiling point",
_ => "Dangerously extreme"
@karenpayneoregon
karenpayneoregon / Program.cs
Created January 6, 2026 03:59
Spectre.Console get date time in 24 hour format
internal partial class Program
{
static void Main(string[] args)
{
var value = Prompts.GetDate();
Console.WriteLine(value.Year == 1 ? "Cancelled" : $"Selected date: {value:dd/MM/yyyy HH:mm}");
Console.ReadLine();
}
}
@karenpayneoregon
karenpayneoregon / Program.cs
Created December 19, 2025 14:48
C# switch's
internal partial class Program
{
static void Main(string[] args)
{
SwitchSamples.Greeting();
Console.WriteLine();
SwitchSamples.GradesTuple();
Console.WriteLine();
SwitchSamples.GroupBook();
}
internal class Program
{
static void Main(string[] args)
{
string userInput = Console.ReadLine();
Console.WriteLine(Convert.ToInt32(userInput));
Console.ReadLine();
@karenpayneoregon
karenpayneoregon / Program.cs
Created December 18, 2025 15:22
December 17 refactored code
using System.Text.Json;
namespace WorkingWithArrays;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press ENTER to exit");