Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

Why people use .AsEnumerable() along with EF query

$
0
0
see the below example and tell me why they use .AsEnumerable() before select ?

they could use select directly.....is not it?

tell me the intention of usage of .AsEnumerable() here in below query?

why they use .ToArray(); instead of Tolist() ?

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;
    }
}

Viewing all articles
Browse latest Browse all 3938

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>