Skip to content

Instantly share code, notes, and snippets.

@hasokeric
Created May 17, 2023 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasokeric/bab707f843b2cf811afbdf16281d24f4 to your computer and use it in GitHub Desktop.
Save hasokeric/bab707f843b2cf811afbdf16281d24f4 to your computer and use it in GitHub Desktop.
Messing Around with JOINs ResourceCal
var resourceGroupRows = Db.ResourceGroup.Where(x => x.Company == Session.CompanyID
&& x.Inactive == false
&&
).ToList();
var resourceCalRows = Db.ResourceCal.Where(x => x.Company == Session.CompanyID
&& x.SpecialDay >= DateTime.Today
).Join(Db.ResourceGroup,
rc => new { rc.Company, rc.ResourceGrpID, Inactive = false },
rg => new { rg.Company, rg.ResourceGrpID, rg.Inactive },
(rc, rg) => rg
).ToList();
var resourceCalRows = Db.ResourceGroup
.Where(rg => Db.ResourceCal.Any(rc => rc.Company == Session.CompanyID
&& rc.SpecialDay >= DateTime.Today
&& rc.ResourceGrpID == rg.ResourceGrpID
&& rc.Company == rg.Company
&& rg.Inactive == false))
.ToList();
var resourceCalRows = Db.ResourceCal
.Where(rc => rc.Company == Session.CompanyID && rc.SpecialDay >= DateTime.Today)
.Join(
Db.ResourceGroup.Where(rg => rg.Inactive == false),
rc => new { rc.Company, rc.ResourceGrpID },
rg => new { rg.Company, rg.ResourceGrpID },
(rc, rg) => rc
)
.ToList();
var resourceCalRows = Db.ResourceCal
.Where(rc => rc.Company == Session.CompanyID && rc.SpecialDay >= DateTime.Today)
.Join(
Db.ResourceGroup,
rc => new { rc.Company, rc.ResourceGrpID },
rg => new { rg.Company, rg.ResourceGrpID },
(rc, rg) => new { ResourceCal = rc, ResourceGroup = rg }
)
.Where(joined => joined.ResourceGroup.Inactive == false)
.Select(joined => joined.ResourceCal)
.ToList();
var resourceCalRows = Db.ResourceCal
.Where(rc => rc.Company == Session.CompanyID
&& rc.SpecialDay >= DateTime.Today
&& Db.ResourceGroup.Any(rg => rg.Company == rc.Company
&& rg.ResourceGrpID == rc.ResourceGrpID
&& rg.Inactive == false))
.ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment