Комментарии:
Does anybody actually know what is going on with this stuff? We see heaps of examples everywhere but no informationon how anything actually works. Typical "aah" moment to be dashed again below by opposing views.
ОтветитьThanks bro for vedios
Ответитьusing System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1
{
public class Program
{
static void Main(string[] args)
{
var db = new ORM();
IEnumerable<Customer> e = db.GetCustomerAsEnumerable();
IQueryable<Customer> q = db.GetCustomerAsQuery();
var highPay = from cust in e
where cust.Revenue < 2500
select cust;
highPay.ToList().ForEach(cust => { Console.WriteLine(cust.Revenue); });
var pay = from customer in q
where customer.Revenue < 2500
select customer;
pay.ToList().ForEach(cust => { Console.WriteLine(cust.Revenue); });
}
}
public class Customer
{
public int Revenue { get; set; }
public Customer(int revenue)
{
Revenue = revenue;
}
}
public class ORM
{
public List<Customer> CustomerList { get; set; } = new List<Customer>();
public ORM()
{
CustomerList.Add(new Customer(225));
CustomerList.Add(new Customer(45));
CustomerList.Add(new Customer(74));
CustomerList.Add(new Customer(435));
CustomerList.Add(new Customer(945));
CustomerList.Add(new Customer(346));
CustomerList.Add(new Customer(349));
CustomerList.Add(new Customer(984));
}
public IQueryable<Customer> GetCustomerAsQuery()
{
return CustomerList.AsQueryable();
}
public IEnumerable<Customer> GetCustomerAsEnumerable()
{
return CustomerList.AsEnumerable();
}
}
}
beautiful, i enjoyed it...simple differences between the two
Ответитьeasy explanation!
ОтветитьThis video just wrong; both IQueryable and IEnumerable will only execute the code when you iterate through the collection. Both implementations have the same impact on the database since the code is converted to SQL when using a ORM. Also, how can you claim that ICollection is faster without providing any data or benchmarks?
ОтветитьIEnumerable<T> is an interface. So in your examples, the IEnumerable<T> also has 0 items--just like IQueryable. It's just an interface that you can use to iterate over the list of items (currently stored in your original List<T>). And you don't get the items until you iterate the collection.
Ответить* support comment *
ОтветитьGreat explanation 👌
ОтветитьLet's be clear here, the only reason why your example worked was that you decided to split the IEnumerable into two separate queries. Had you used the Where() extension method in the declaration of your enumerable object, and you would also have only returned 2500 customers through the network. In your example, there's actually no advantage in using one over the other. I think you can make a better video explaining the differences between IQueryable and IEnumerable if you focus on its actual benefits: With IQueryable, you can more easily compose queries dynamically based on runtime conditions. And you should avoid examples where you use IQueryable outside your ORM layer, unless you make it clear that doing so is actually not going to allow you to easily replace your ORM in the future.
Ответитьthank you bro i understand it and i think there is no missing part. :)
ОтветитьIEnumerable is NOT a real collection
ОтветитьNice video understood totally.
ОтветитьWell explained.
ОтветитьThank you for an amazing and easy explanation!
ОтветитьVery well explained, using it from long time, but donot know the differences 😢
ОтветитьFinally, I got it. Thank you so much!
ОтветитьSo helpful. Thanks a lot
ОтветитьAwesome
Ответить