Skip to content

Instantly share code, notes, and snippets.

@margusmartsepp
Created April 1, 2016 11:48
Show Gist options
  • Save margusmartsepp/28d3937db8eebe26a1190722fa56e0f2 to your computer and use it in GitHub Desktop.
Save margusmartsepp/28d3937db8eebe26a1190722fa56e0f2 to your computer and use it in GitHub Desktop.
Ef7 query test
using System;
using System.Linq;
using Microsoft.Data.Entity;
namespace Ef7Tests
{
internal class Program
{
/// <summary>
/// <para /> Nuget packages:
/// <para /> * Install-Package EntityFramework.MicrosoftSqlServer -Pre
/// <para /> * Install-Package EntityFramework.Commands -Pre
/// <para /> Create database:
/// <para /> * Add-Migration EfMultipleV1
/// <para /> * Update-Database
/// </summary>
private static void Main(string[] args)
{
//test 1
using (var ctx = new MultipleContext())
{
foreach (var count in new[] { 1, 3, 10, 30, 100, 300, 1000, 3000 })
{
foreach (var multiple in Enumerable.Range(1, count))
{
ctx.Multiples.Add(new Multiple { Counter = multiple, Name = $"Single Insert Set: {count}" });
}
ctx.SaveChanges();
}
foreach (var count in new[] { 1, 3, 10, 30, 100, 300, 1000, 3000 })
{
var multiples = Enumerable.Range(1, count)
.Select(multiple => new Multiple {Counter = multiple, Name = $"Multiple Insert Set: {count}"});
ctx.Multiples.AddRange(multiples);
ctx.SaveChanges();
}
}
}
public class MultipleContext : DbContext
{
public DbSet<Multiple> Multiples { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
@"Server=(local);Database=EF7.ConsoleTests;Trusted_Connection=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Multiple>().Property(o => o.Added).HasDefaultValueSql("getutcdate()");
modelBuilder.Entity<Multiple>().Property(o => o.Counter).IsRequired();
}
}
public class Multiple
{
public int Id { get; set; }
public int Counter { get; set; }
public string Name { get; set; }
public DateTime Added { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment