please see the below code
- private IEnumerable<AutoCompleteData> GetAutoCompleteData(string searchTerm)
- {
- using (var context = new AdventureWorksEntities())
- {
- var results = context.Products
- .Include("ProductSubcategory")
- .Where(p => p.Name.Contains(searchTerm)
- && p.DiscontinuedDate == null)
- .AsEnumerable()
- .Select(p => new AutoCompleteData
- {
- Id = p.ProductID,
- Text = BuildAutoCompleteText(p)
- })
- .ToArray();
- return results;
- }
- }
please tell me why someone use .AsEnumerable() before select?
i use EF to fetch data but i never use .AsEnumerable() before select but some one used. it means there must be some reason to use there .AsEnumerable().
please discuss the significance of using .AsEnumerable() before select there?
if we remove .AsEnumerable() from EF query then does it execute and return data ?
here is my example for fetching data where i have not used AsEnumerable()
- var customer = (from s in db.Customers
-
- select new CustomerDTO
- {
- CustomerID = s.CustomerID,
- CompanyName = s.CompanyName,
- ContactName = s.ContactName,
- ContactTitle = s.ContactTitle,
- Address = s.Address
- });
thanks