Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with string array? Pin
Dave Kreskowiak4-Jul-23 7:06
mveDave Kreskowiak4-Jul-23 7:06 
AnswerRe: Problem with string array? Pin
OriginalGriff4-Jul-23 18:21
mveOriginalGriff4-Jul-23 18:21 
GeneralRe: Problem with string array? Pin
jschell5-Jul-23 5:28
jschell5-Jul-23 5:28 
QuestionPredicateBuilder Question Pin
Kevin Marois30-Jun-23 8:54
professionalKevin Marois30-Jun-23 8:54 
AnswerRe: PredicateBuilder Question Pin
Dave Kreskowiak1-Jul-23 4:23
mveDave Kreskowiak1-Jul-23 4:23 
GeneralRe: PredicateBuilder Question Pin
Kevin Marois1-Jul-23 8:21
professionalKevin Marois1-Jul-23 8:21 
AnswerRe: PredicateBuilder Question Pin
BillWoodruff1-Jul-23 9:54
professionalBillWoodruff1-Jul-23 9:54 
AnswerRe: PredicateBuilder Question Pin
James Curran5-Jul-23 10:41
James Curran5-Jul-23 10:41 
There are a couple things to be done here:
C#
(from j in dc.Jobs
                select j)
That, by itself, isn't doing much, except adding a pointless loop. "dc.Jobs" by itself, will do the same thing.
C#
// Define the query parameters for the job
var jobPredicate = PredicateBuilder.New<Job>();
jobPredicate = jobPredicate.And(x => x.AppCompanyId == 1);
jobPredicate = jobPredicate.And(x => !x.DeletedDT.HasValue);
Unless there are some logic you've left out, which makes this optional, building the predicate this way is unnecessary. So, unless you have something like:
C#
// Define the query parameters for the job
var jobPredicate = PredicateBuilder.New<Job>();
if (forApp1only)
     jobPredicate = jobPredicate.And(x => x.AppCompanyId == 1);
if (!includeDeleted)
     jobPredicate = jobPredicate.And(x => !x.DeletedDT.HasValue);
you could instead use just:
dc.Jobs.Where(job=> job.AppCompanyId == 1 && !job.DeletedDT.HasValue)
Which would mean your solution is just:
var job = dc.Jobs
                 .Where(job=> job.AppCompanyId == 1 && !job.DeletedDT.HasValue && job.Id == vendorAssignment.ParentId)
                 .FirstOrDefault();

But, let's say you really do need to use PredicateBuilder, still no problem, as you can repeat Where clauses:
var job = dc.Jobs
                 .Where(jobPredicate)
                 .Where(job=> job.Id == vendorAssignment.ParentId)
                 .FirstOrDefault();

Which we can shorten to:
var job = dc.Jobs
                 .Where(jobPredicate)
                 .FirstOrDefault(job=> job.Id == vendorAssignment.ParentId)
Truth,

James

QuestionUnable to Receive data from Cobas e411 Serial Port Pin
Member 1493027227-Jun-23 22:20
Member 1493027227-Jun-23 22:20 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
Richard MacCutchan27-Jun-23 23:08
mveRichard MacCutchan27-Jun-23 23:08 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
OriginalGriff27-Jun-23 23:38
mveOriginalGriff27-Jun-23 23:38 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
Ralf Meier28-Jun-23 0:43
mveRalf Meier28-Jun-23 0:43 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
jschell28-Jun-23 6:08
jschell28-Jun-23 6:08 
GeneralRe: Unable to Receive data from Cobas e411 Serial Port Pin
Member 1493027228-Jun-23 6:21
Member 1493027228-Jun-23 6:21 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
Gerry Schmitz28-Jun-23 6:51
mveGerry Schmitz28-Jun-23 6:51 
QuestionGoogle PeopleAPI & HttpListener Redirect URI Pin
Kevin Marois22-Jun-23 10:03
professionalKevin Marois22-Jun-23 10:03 
AnswerRe: Google PeopleAPI & HttpListener Redirect URI Pin
jschell23-Jun-23 10:45
jschell23-Jun-23 10:45 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
Kevin Marois23-Jun-23 12:18
professionalKevin Marois23-Jun-23 12:18 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
Richard Andrew x6425-Jun-23 11:44
professionalRichard Andrew x6425-Jun-23 11:44 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
Kevin Marois25-Jun-23 17:41
professionalKevin Marois25-Jun-23 17:41 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
jschell26-Jun-23 5:31
jschell26-Jun-23 5:31 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
Kevin Marois26-Jun-23 8:20
professionalKevin Marois26-Jun-23 8:20 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
Kevin Marois26-Jun-23 16:19
professionalKevin Marois26-Jun-23 16:19 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
jschell27-Jun-23 4:48
jschell27-Jun-23 4:48 
General[UPDATE] - Google PeopleAPI & HttpListener Redirect URI Pin
Kevin Marois27-Jun-23 6:01
professionalKevin Marois27-Jun-23 6:01 

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.