Returning IQueryable or Enumerated Object
Posted
by Tarik
on Stack Overflow
See other posts from Stack Overflow
or by Tarik
Published on 2010-04-07T05:42:44Z
Indexed on
2010/04/07
6:03 UTC
Read the original article
Hit count: 690
Hello everyone,
I was wondering about the performance difference between these two scenarios and what could the disadvantages be over each other?
First scenario :
public class Helper //returns IQueryable
{
public IQueryable<Customer> CurrentCustomer
{
get{return new DataContext().Where(t=>t.CustomerId == 1);
}
}
public class SomeClass
{
public void Main()
{
Console.WriteLine(new Helper().CurrentCustomer.First().Name;
}
}
The second scenario :
public class Helper //returns Enumerated result
{
public Customer CurrentCustomer
{
get{return new DataContext().First(t=>t.CustomerId == 1);
}
}
public class SomeClass
{
public void Main()
{
Console.WriteLine(new Helper().CurrentCustomer.Name;
}
}
Thanks in advance.
© Stack Overflow or respective owner