Skip to content

Instantly share code, notes, and snippets.

Wullems Bart wullemsb

Block or report user

Report or block wullemsb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View CheckPendingMigrations.cs
if (!Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("local", StringComparison.OrdinalIgnoreCase))
{
var serviceProvider = services.BuildServiceProvider();
using (var ctx = serviceProvider.GetService<SampleContext>())
{
var pendingMigrations = ctx.Database.GetPendingMigrations().ToList();
if (pendingMigrations.Any())
{
throw new Exception(
$@"Please contact the administrator. The following database migrations are pending:
View GetProductsDiscontinued.cs
[HttpGet]
public ActionResult<IEnumerable<Product>> Get()
{
_logger.LogInformation("Getting all products");
using (var uow = _unitOfWorkFactory.Create())
{
var products = _repository
.GetProducts()
.Where(p=> p.Discontinued=false);
View GetProducts.cs
// GET api/products
[HttpGet]
public ActionResult<IEnumerable<Product>> Get()
{
_logger.LogInformation("Getting all products");
using (var uow = _unitOfWorkFactory.Create())
{
var products = _repository.GetProducts();
return products;
}
View TaggedQueries.cs
await dataContext.Products
.TagWith("All-Products-Query")
.ToListAsync();
View web.config
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="true" name="AppNameAuth" />
<wsFederation passiveRedirectEnabled="false" issuer="https://adfs2.vlm.be/adfs/ls/" realm="https://localhost/AppName/FederationResult/" requireHttps="true" />
</federationConfiguration>
</system.identityModel.services>
View SampleDbContext.cs
public class SampleDbContext : DbContext
{
public SampleDbContext(DbContextOptions options)
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
View StringExtensions.cs
public static class StringExtensions
{
public static string ToSnakeCase(this string input)
{
var startUnderscores = Regex.Match(input, @"^_+");
return startUnderscores + Regex.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2").ToLower();
}
}
View killconnections.sql
SELECT
pg_terminate_backend (pg_stat_activity.pid)
FROM
pg_stat_activity
WHERE
pg_stat_activity.datname = 'sampledb';
View ModelBuilder.cs
modelBuilder.Entity<MyEntity>()
.Id(e=> e.Id)
.Property(e => e.Strings)
.HasConversion(
v => string.Join(',', v),
v => v.Split(',', StringSplitOptions.RemoveEmptyEntries));
You can’t perform that action at this time.