Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Trying to use and condition in Linq Query with join and on C#

Trying to use and condition in Linq Query with join and on C#

Scheduled Pinned Locked Moved C#
csharphelpdatabaselinqquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simpledeveloper
    wrote on last edited by
    #1

    Hi I have a linq Query as below

    Query A:
    from a in violations
    join b in programs on a.ViolationTypeId equals b.ViolationTypeId
    join d in branches on b.BranchId equals d.BranchId
    join e in subprograms on a.ViolationSubtypeId equals e.ViolationTypeId into es
    from e in es.DefaultIfEmpty()
    join f in nonUniquePenalties on a.ViolationSubtypeId equals f.ViolationTypeId && f.ParentViolationTypeId==a.ViolationTypeId
    where a.ApplyUniquePenalty == true

    And I have an another Collection with name: nonUniquePenalties, which has ViolationTypeId and ParentViolationTypeId. the problem that I have is: violations has two fields, ViolationSubtypeId which can be null and ViolationTypeId can not null. Now I want to left join nonUniquePenalties such a way that, if violations doesn't have ViolationSubtypeId , it has to check only for ViolationTypeId of violations and ParentViolationTypeId of nonUniquePenalties, if violations has ViolationSubtypeId and ViolationTypeId, linq has to check for ViolationSubtypeId of violations with ViolationTypeId and ViolationTypeId of violations with ParentViolationTypeId of nonUniquePenalties. Any help please? And it has to be left outer join with other collections, since if there is no values in nonUniquePenalties, still the lnq should yield records. I tried a little bit, but any help would be very helpful, thanks in advance.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups