Click here to Skip to main content
14,176,639 members
Rate this:
Please Sign up or sign in to vote.
See more:
hey guys I am trying to write this query in my Business Object class, when I try to return var matchingChild I get an error message as above
public static List<Case_MC_ReporterView> Search(string txt)

    List<Case_MC_ReporterView> l = new  List<Case_MC_ReporterView>();

    MissingChildDBDataContext db = new MissingChildDBDataContext();
    var matchingChild = from children in db.Case_MC_ReporterViews
                        where children.MC_FirstName.StartsWith(txt)
                        select children;
    return matchingChild;


Can anybody help me with this?
many Thanks,

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Instead of
return matchingChild;

return matchingChild.ToList();

All Linq to sql Queries use a mechanism microsoft calls
Deferred execution, which means the query is not realy executed until you enumerate it (Go Over the results).
When you enumerate the results with
1) ToList
2) ToArray
3) FirstOrDefault, First
4) SingOrDefault, Single
5) Count
Etc, etc...

Which are all extension methods of IEnumerable Interface
(Which IQueryable Inherits from)

So instead of returning the deferred query, just do a to list operation.
cnjadhav 19-Aug-10 11:02am
I tried using return matchingChild.ToList();
and still getting the same error
Shani Natav 19-Aug-10 11:08am
Can You Paste the whole error? It seems you cut off most of it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190525.1 | Last Updated 19 Aug 2010
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100