-
-
Save anonymous/d271f4ca0276cca7d481 to your computer and use it in GitHub Desktop.
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 Employee | |
{ | |
[Key] | |
public virtual int EmployeeId { get; protected set; } | |
[StringLength(100)] | |
public virtual string FirstName { get; set; } | |
[StringLength(100)] | |
public virtual string LastName { get; set; } | |
} | |
public class EmployeeMap : ClassMap<Employee> | |
{ | |
public EmployeeMap() | |
{ | |
Id(x => x.EmployeeId); | |
Map(x => x.FirstName) | |
.Length(100); | |
Map(x => x.LastName) | |
.Length(100); | |
Table("Employees"); | |
} | |
} | |
static void EF_Select() | |
{ | |
using (var context = new MyContext()) | |
{ | |
var pppp = context.Persons.Where(p => p.EmployeeId == 0).SingleOrDefault(); | |
DateTime start = DateTime.Now; | |
int aggr = 0; | |
foreach (var pp in context.Persons.Where(p => p.EmployeeId > 1) | |
.Select(p => new { p.EmployeeId, p.FirstName, p.LastName })) | |
{ | |
aggr += pp.EmployeeId; | |
} | |
Console.WriteLine(string.Format("EF select {0};", DateTime.Now - start)); | |
} | |
} | |
private static void NHibernate_Select() | |
{ | |
var sessionFactory = CreateSessionFactory(); | |
using (var session = sessionFactory.OpenStatelessSession()) | |
{ | |
var pppp = session.Query<Employee>().Where(p => p.EmployeeId == 0).SingleOrDefault(); | |
DateTime start = DateTime.Now; | |
int aggr = 0; | |
foreach (var pp in session.Query<Employee>().Where(p => p.EmployeeId > 1) | |
.Select(p => new { p.EmployeeId, p.FirstName, p.LastName })) | |
{ | |
aggr += pp.EmployeeId; | |
} | |
Console.WriteLine(string.Format("NH select {0};", DateTime.Now - start)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment