Click here to Skip to main content
12,451,243 members (55,747 online)
   

LINQ

 
QuestionLINQ or ADO.NET ? Pin
pashmakjoon19-Aug-12 10:11
memberpashmakjoon19-Aug-12 10:11 
AnswerRe: LINQ or ADO.NET ? Pin
Richard MacCutchan19-Aug-12 23:03
mvpRichard MacCutchan19-Aug-12 23:03 
AnswerRe: LINQ or ADO.NET ? Pin
thatraja20-Aug-12 0:39
mvpthatraja20-Aug-12 0:39 
GeneralRe: LINQ or ADO.NET ? Pin
manijasmine20-Aug-12 8:07
membermanijasmine20-Aug-12 8:07 
AnswerRe: LINQ or ADO.NET ? PinPopular
Kolkata .NET8-Mar-13 5:45
memberKolkata .NET8-Mar-13 5:45 
Questionhow to load and save an xml document using linq Pin
owobs15-Aug-12 1:57
memberowobs15-Aug-12 1:57 
AnswerRe: how to load and save an xml document using linq Pin
Wayne Gaylard15-Aug-12 2:16
mentorWayne Gaylard15-Aug-12 2:16 
QuestionCreating a dynamic where clause Pin
Simon_Whale9-Aug-12 0:06
memberSimon_Whale9-Aug-12 0:06 
I have the requirements to change a method, in particular a LINQ query to return results on various permutations of 2 variables (Postcode, Surname) which would result in changing the where clause as shown in the highlighted row below. But instead of re-writing the statement for the 3 different where clauses I want to be able to reuse as much as possible.

var PeopleRecordsSearch = from SomePeople in Person()
                                        join SomeClient in Client() on SomePeople.PersonID equals SomeClient.PersonID
                                        where SomePeople.Surname.Contains(Surname) && SomePeople.Surname.Length > 0 && SomeClient.Postcode == Postcode 
                                        select SomePeople;

I have looked at using the Func which works great when the results (i.e. the select statement) are the same as the in variable i.e.

Func<Tables.Person, bool> WhereSurname = p => p.Surname = Surname;

which I can run then as

PeopleRecordSearch.Where(WhereSurname).ToList();

but if I want to search the Postcode of the Client table with this

Func<Tables.Client, bool> WherePostcode = p => p.Postcode == Postcode;

I get the following error in Visual Studio

Argument 2: cannot convert from 'System.Func' to 'System.Linq.Expressions.Expression>' Person.cs 125 69

Which I know is the Func statement.

My question is, is there a way that I can re use the main body of the query and write a dynamic where clause into the statement or the results by doing PeopleRecordSearch.Where(FuncArgument).ToList();?


Thanks
Simon
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

AnswerRe: Creating a dynamic where clause Pin
Pete O'Hanlon9-Aug-12 0:22
protectorPete O'Hanlon9-Aug-12 0:22 
GeneralRe: Creating a dynamic where clause Pin
Simon_Whale9-Aug-12 0:26
memberSimon_Whale9-Aug-12 0:26 
GeneralRe: Creating a dynamic where clause Pin
BobJanova9-Aug-12 2:11
memberBobJanova9-Aug-12 2:11 
GeneralRe: Creating a dynamic where clause Pin
Simon_Whale9-Aug-12 3:10
memberSimon_Whale9-Aug-12 3:10 
GeneralRe: Creating a dynamic where clause Pin
Pete O'Hanlon9-Aug-12 3:40
protectorPete O'Hanlon9-Aug-12 3:40 
GeneralRe: Creating a dynamic where clause Pin
Simon_Whale9-Aug-12 3:44
memberSimon_Whale9-Aug-12 3:44 
QuestionLinq where dates question Pin
Member 78188928-Jul-12 13:23
memberMember 78188928-Jul-12 13:23 
AnswerRe: Linq where dates question Pin
Pete O'Hanlon8-Jul-12 19:51
protectorPete O'Hanlon8-Jul-12 19:51 
AnswerRe: Linq where dates question Pin
BobJanova9-Jul-12 1:41
memberBobJanova9-Jul-12 1:41 
AnswerRe: Linq where dates question Pin
Matt T Heffron11-Jul-12 8:41
memberMatt T Heffron11-Jul-12 8:41 
AnswerRe: Linq where dates question Pin
Matt T Heffron27-Jul-12 14:35
memberMatt T Heffron27-Jul-12 14:35 
Questionlinq to sql connection string name Pin
rachel_m6-Jul-12 6:31
memberrachel_m6-Jul-12 6:31 
AnswerRe: linq to sql connection string name Pin
BobJanova9-Jul-12 1:42
memberBobJanova9-Jul-12 1:42 
QuestionConvert SQL to LINQ Pin
divesh123-Jul-12 9:47
memberdivesh123-Jul-12 9:47 
QuestionRe: Convert SQL to LINQ Pin
Naerling12-Jul-12 6:01
memberNaerling12-Jul-12 6:01 
AnswerRe: Convert SQL to LINQ Pin
thatraja20-Aug-12 0:32
mvpthatraja20-Aug-12 0:32 
AnswerRe: Convert SQL to LINQ Pin
Emmanuel Medina Lopez18-Sep-12 8:40
memberEmmanuel Medina Lopez18-Sep-12 8:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 10 Aug 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid