Skip to content

Instantly share code, notes, and snippets.

@rafaelpadovezi
Created May 21, 2020 13:12
Show Gist options
  • Save rafaelpadovezi/d6869ec2d08c9c3c008d87f28b81c806 to your computer and use it in GitHub Desktop.
Save rafaelpadovezi/d6869ec2d08c9c3c008d87f28b81c806 to your computer and use it in GitHub Desktop.
public class Contract
{
public int Id { get; set; }
public string Url { get; set; }
}
public class ModelContext : DbContext
{
public static readonly ILoggerFactory DebugLoggerFactory
= LoggerFactory.Create(builder => { builder.AddDebug(); });
public virtual DbSet<Contract> ContractType { get; set; }
public ModelContext(DbContextOptions<ModelContext> options) : base(options) {}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder
.UseLoggerFactory(DebugLoggerFactory)
.EnableSensitiveDataLogging();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Contract>(entity =>
{
entity.ToTable("CONTRACT");
entity.Property(e => e.Id).HasColumnName("ID");
entity.Property(e => e.Url)
.HasColumnName("URL")
.HasColumnType("VARCHAR2(100)");
});
}
}
public class DbContextTests
{
[Test]
public void NonUnicode_Coalesce()
{
using var context = new ModelContext(new DbContextOptionsBuilder<ModelContext>()
.UseOracle("my_connection_string")
.Options);
string sqlQuery = context.ContractType
.Select(x => x.Url ?? "-")
.FirstOrDefault();
Assert.Pass();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment