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
<!DOCTYPE html> | |
<html lang='en'> | |
<head> | |
<meta charset='utf-8' /> | |
<title>LinqBenchmarks.LinqBenchmark-20240119-231018</title> | |
<style type="text/css"> | |
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; } | |
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; } | |
tr { background-color: #fff; border-top: 1px solid #ccc; } |
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
public static class EntityTypeConfigurationExtensions | |
{ | |
private static readonly MethodInfo EntityMethod = typeof(ModelBuilder).GetTypeInfo().GetMethods().Single(x => x.Name == "Entity" && x.IsGenericMethod && x.GetParameters().Length == 0); | |
private static readonly IDictionary<Assembly, IEnumerable<Type>> TypesPerAssembly = new Dictionary<Assembly, IEnumerable<Type>>(); | |
private static Type GetEntityType(Type type) | |
{ | |
Type interfaceType = type.GetInterfaces().First(x => x.GetTypeInfo().IsGenericType && x.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>)); | |
return interfaceType.GetGenericArguments().First(); | |
} |
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
public class AdventureWorks2014Context : DbContext | |
{ | |
public AdventureWorks2014Context() | |
: base("Name=AdventureWorks2014Context") | |
{ | |
} | |
protected override void OnModelCreating(DbModelBuilder modelBuilder) | |
{ | |
modelBuilder.Configurations.Add(new ShiftMap()); |
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
public class AdventureWorksDbContext : DbContext | |
{ | |
public AdventureWorksDbContext(DbContextOptions options) : base(options) | |
{ | |
} | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder.UseEntityTypeConfiguration(); |
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
public class ShiftMap : EntityTypeConfiguration<Shift> | |
{ | |
public ShiftMap() | |
{ | |
// Table & Column Mappings | |
this.ToTable("Shift", "HumanResources"); | |
// Primary Key | |
this.HasKey(t => t.ShiftID); |
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
public sealed class ShiftMap : IEntityTypeConfiguration<Shift> | |
{ | |
public void Map(EntityTypeBuilder<Shift> builder) | |
{ | |
// table | |
builder.ToTable("Shift", "HumanResources"); | |
// keys | |
builder.HasKey(t => t.ShiftID); |
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
public interface IEntityTypeConfiguration<TEntity> where TEntity : class | |
{ | |
void Map(EntityTypeBuilder<TEntity> entityTypeBuilder); | |
} |
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
static class ModelBuilderExtensions | |
{ | |
private static readonly Assembly EntitiesAssembly = typeof(AdventureWorksDbContext).Assembly; | |
private static readonly Type EntityActiveableType = typeof(IEntityActiveable); | |
private static readonly MethodInfo EntityMethod = typeof(ModelBuilder).GetTypeInfo().GetMethods().Single(x => x.Name == "Entity" && x.IsGenericMethod && x.GetParameters().Length == 0); | |
private static IList<Type> _activeablesTypes; | |
private static IList<Type> ActiveablesTypes | |
{ | |
get { return _activeablesTypes ?? (_activeablesTypes = EntitiesAssembly.ExportedTypes.Where(t => t.IsClass && t.IsPublic && EntityActiveableType.IsAssignableFrom(t)).ToList()); } |
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
public class BaseController : Controller | |
{ | |
protected readonly AdventureWorksDbContext _adventureWorksDbContext; | |
protected static readonly JsonSerializerSettings DefaultJsonSerializerSettings = new JsonSerializerSettings | |
{ | |
NullValueHandling = NullValueHandling.Ignore, | |
ContractResolver = new CamelCasePropertyNamesContractResolver(), | |
DateTimeZoneHandling = DateTimeZoneHandling.Utc | |
}; |
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
public class AdventureWorksDbContext : DbContext | |
{ | |
public AdventureWorksDbContext(DbContextOptions options) : base(options) | |
{ | |
} | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
// table |
NewerOlder