Created
April 24, 2013 19:12
-
-
Save raghuramn/5454730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Collections.Generic; | |
using System.Data.Entity; | |
using System.Linq; | |
namespace QueryTests | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//RecreateDB(); | |
using (CustomersContext db = new CustomersContext()) | |
{ | |
int count = db.Customers.Where(c => c.Age == 26).Count(); | |
Console.WriteLine(count); | |
bool moreThanOne = db.Customers.Where(c => c.Age == 26).OrderBy(c => c.ID).Skip(1).Any(); | |
Console.WriteLine(moreThanOne); | |
} | |
} | |
private static void RecreateDB() | |
{ | |
using (CustomersContext db = new CustomersContext()) | |
{ | |
db.Database.Delete(); | |
db.Database.Create(); | |
db.SaveChanges(); | |
} | |
for (int j = 0; j < 100; j++) | |
{ | |
using (CustomersContext db = new CustomersContext()) | |
{ | |
Random r = new Random(); | |
for (int i = 0; i < 1000; i++) | |
{ | |
Customer c = new Customer | |
{ | |
Name = Guid.NewGuid().ToString(), | |
Age = r.Next(0, 100) | |
}; | |
db.Customers.Add(c); | |
} | |
db.SaveChanges(); | |
} | |
Console.WriteLine(j); | |
} | |
} | |
} | |
public class Customer | |
{ | |
public int ID { get; set; } | |
public string Name { get; set; } | |
public int Age { get; set; } | |
} | |
public class CustomersContext : DbContext | |
{ | |
public DbSet<Customer> Customers { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment