Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
XML
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,
Chetan.
Posted

1 solution

Instead of
C#
return matchingChild;


write
C#
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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900