Created
June 19, 2015 19:46
-
-
Save natemcmaster/039c66671b18894c64f7 to your computer and use it in GitHub Desktop.
EF Issue 2057
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Data.Entity; | |
namespace ConsoleApp1 | |
{ | |
public class MyContext : DbContext | |
{ | |
public DbSet<Address> Addresses { get; set; } | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
{ | |
optionsBuilder.UseSqlServer(@"Server=(localdb)\MSSqlLocalDb;Database=scratch-91"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
using Microsoft.Framework.DependencyInjection; | |
using Microsoft.Framework.Logging; | |
namespace ConsoleApp1 | |
{ | |
public class Program | |
{ | |
public void Main(string[] args) | |
{ | |
var logger = new SimpleLoggerFactory(); | |
var serviceCollection = new ServiceCollection(); | |
serviceCollection | |
.AddInstance<ILoggerFactory>(logger) | |
.AddEntityFramework() | |
.AddSqlServer() | |
.AddDbContext<MyContext>(); | |
var provider = serviceCollection.BuildServiceProvider(); | |
using (var _db = provider.GetService<MyContext>()) | |
{ | |
// _db.Database.AsRelational().EnsureCreated(); | |
_db.Addresses.Where(x => x.Discriminator == Discriminator.Something).ToList(); | |
} | |
var sql = logger.Instance.Sb.ToString(); | |
Console.WriteLine(sql); | |
Debug.Assert(sql.Contains("@__p_0: 1")); | |
Console.ReadLine(); | |
} | |
} | |
public class Address | |
{ | |
public int Id { get; set; } | |
public Discriminator Discriminator { get; set; } | |
} | |
public enum Discriminator | |
{ | |
Something = 1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "1.0.0-*", | |
"description": "", | |
"authors": [ "" ], | |
"tags": [ "" ], | |
"projectUrl": "", | |
"licenseUrl": "", | |
"dependencies": { | |
"EntityFramework.SqlServer": "7.0.0-*" | |
}, | |
"commands": { | |
"ConsoleApp1" : "ConsoleApp1" | |
}, | |
"frameworks" : { | |
"dnx451": { }, | |
"dnxcore50" : { | |
"dependencies": { | |
"System.Console": "4.0.0-*", | |
"System.Collections": "4.0.10-*", | |
"System.Linq": "4.0.0-*", | |
"System.Threading": "4.0.10-*", | |
"Microsoft.CSharp": "4.0.0-*" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using Microsoft.Framework.Logging; | |
namespace ConsoleApp1 | |
{ | |
public class SimpleLoggerFactory : ILoggerFactory | |
{ | |
public SimpleLogger Instance { get; } = new SimpleLogger(); | |
public ILogger CreateLogger(string categoryName) | |
{ | |
return Instance; | |
} | |
public void AddProvider(ILoggerProvider provider) | |
{ | |
} | |
public LogLevel MinimumLevel { get; set; } | |
public class SimpleLogger : ILogger | |
{ | |
public StringBuilder Sb { get; } = new StringBuilder(); | |
public void Log(LogLevel logLevel, int eventId, object state, Exception exception, | |
Func<object, Exception, string> formatter) | |
{ | |
if (formatter == null || eventId != 42) | |
return; | |
Sb.AppendLine(formatter(state, exception)); | |
} | |
public bool IsEnabled(LogLevel logLevel) => true; | |
public IDisposable BeginScopeImpl(object state) | |
{ | |
return new NullScope(); | |
} | |
public class NullScope : IDisposable | |
{ | |
public void Dispose() | |
{ | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment