Tuesday 15 September 2015

asp.net mvc - How do I add a where clause to a field that is not part of the return set for LINQ query -


I'm thinking how I would add a dynamic where my Linux query is on the clause where the field I'm filing returns set part

Q:

  (db.Person in c in c_join c in c_join.DefaultIfEmpty joining c db.Client P p.PersonId. having equals PersonId is () equals pt.PersonTypeId in pt_join of pt in pt_join.DefaultIfEmpty include pl in db.Plan on CkClientId (join pt in db.PersonType on p.PersonTypeId) pl In _join.DefaultIfEmpty equals pl.ClientId in pl_join from pl () plt_join.DefaultIfEmpty (in db.PlanType pl.PlanTypeId join Plt) in plt_join from Plt in orderby pt.PersonTypeDescription ascending, p.LastName ascending select equals plt.PlanTypeId new ExtendedPersonSearch {PersonId = p.PersonId, FirstName = p.FirstName, LastName = p.LastName, MiddleName = p.MiddleName, aka = p.Aka, sin = p.Sin, PersonTypeId = pt.PersonTypeId, PersonTypeDescription = pt.PersonTypeDescription, clientid = (Int32?) C.ClientId}) different () .;   

Related category:

  Public category Extended SparkSearch {Public Entity ID {Receipt; Set; } Public string first name {receives; Set; } Public String LastName {get; Set; } Public string middlename {get; Set; } Public String Aka {get; Set; } Public string sin {get; Set; } Receive Public Entity Insurance ID { Set; } Public string PersonTypeDescription {get; Set; } Public int? Address ID {Receive; Set; } Receive Public String Street 1; Set; } Public int? Get Client ID { Set; }   

However, I want to filter on pl.PlanId which is not part of the Extended Detector Search Class.

These are other types of dynamic where work for segment items inside the return set:

  if (fd.Contains ("txtSearchFirstName")) {var searchFirstName = Form [fd]; ViewData ["searchFirstName"] = searchFirstName; If (searchFirstName! = "") QryAllPerson = qryAllPerson.Where (sp = & gt; sp.FirstName.Contains (searchFirstName)); }   

To retrieve this query, rewrite the query based on whether or not a user entered a plan ID:

  qryAllPerson = (p being db.Person joining the c db.Client on p.PersonId equals c.PersonId in c_join c in c_join.DefaultIfEmpty () includes pt in db.PersonType on p.PersonTypeId in pt_join equals pt.PersonTypeId in pt_join from pt. to include default IfEmpty () pl in db.Plan on c.ClientId pl_join pl_join.DefaultIfEmpty (in pl_join in pl_join) in plt sh Get pl.PlanType pl.PlanTypeId in plt.PlanTypeIt plt_join plt_join in plt_join.DefaultIfEmpty in plt_join ()) orderby pt.PersonTypeDescription ascending, p.LastName ascending where pl.PlanId == searchPlanId New ExtendedPersonSearch {PersonId = p.PersonId , FirstName = p.FirstName, Select LastName = p.LastName, MiddleName = p.MiddleName, aka = P. Aka, sin = p.Sin, PersonTypeId = pt.PersonTypeId, PersonTypeDescription = pt.PersonTypeDescription, clientid = (Int32?) C.ClientId}) different () .;   

Is there no way that I can attack the scheme ID instead of completely replacing the whole query?

Other dynamic searches work because they have properties on your expanded search class.

When you run your query, you are returning the calculation of Extended PersonSearch objects. Once you take it back, you can filter it only on the basis of the properties on that object.

Just like real life, you have not been able to filter your pets with the number of CPU cores they have (it just can not understand.)

If you In a single query, you can modify the line

  where pl.PlanId == searchPlanId   

be

  Where (searchPlanId == tap || pl.planId == searchPlanId)   

In this way if no search plan has been entered, the first part of the conditional has been hit and it Short circuit and all records The power returns. If a search plan ID is entered, then the first segment is false, and therefore go to C # the second block and make sure that the search entered by pl.PlanId is equal to the search ID.

Or you can add plan IDs to filter it after you recover from the extended PersonSearch object and data source. But this is probably not the best idea, because you throw away a lot of data and only throw your best, when you take the results, which do not match the scheme ID.

No comments:

Post a Comment