TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tridip Bhattacharjee
NA
1.2k
77.6k
When to use AsEnumerable() along with EF to fetch data
Feb 12 2018 3:08 AM
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 s;
select
new
CustomerDTO
{
CustomerID = s.CustomerID,
CompanyName = s.CompanyName,
ContactName = s.ContactName,
ContactTitle = s.ContactTitle,
Address = s.Address
});
thanks
Reply
Answers (
3
)
SQL Query to LINQ Conversion
MVC Search by Id which is int type: