I need to return true when any record either has an Indemnity type of bond, or has the bond waived. I think because of the way inner joins are happening this is not working.
var HasBondorWaived = (from a in context.Allocations
join p in context.Permits on a.PermitGUID equals p.GUID
join i in context.Indemnities on a.IndemnityGUID equals i.GUID
join t in context.IndemnityTypes on a.IndemnityAreaTypeGUID equals t.GUID
where (p.GUID.Equals(PermitGuid)
&& (t.Description.Equals("Performance Bonds") || t.Description.Equals("Payment Bonds")))
|| p.BondRequirementWaived where p.GUID.Equals(PermitGuid)
select a).Any();
return HasBondorWaived;
I'm getting closer. My validation is now working correctly in the case of "Performance Bond" or "Payment Bond", but is not working in the case of BondRequirementWaved. This is a bool in the EF, and a bit in SQL server. In the case of BondRequirementWaved, it is returning false.
using (var context = new KEPTEntities())
{
var HasBondorWaived = (from a in context.Allocations
join p in context.Permits on a.PermitGUID equals p.GUID
join i in context.Indemnities on a.IndemnityGUID equals i.GUID
join t in context.IndemnityTypes on i.IndemnityTypeGUID equals t.GUID
where (p.GUID.Equals(PermitGuid)
&& (t.Description.Equals("Performance Bonds")
|| t.Description.Equals("Payment Bonds")
|| p.BondRequirementWaived))
select a).Any();
return HasBondorWaived;
The second where clause won't work as you expect. You need to remove it.
You probably want this:
where (p.GUID.Equals(PermitGuid)
&& (t.Description.Equals("Performance Bonds") || t.Description.Equals("Payment Bonds")
|| p.BondRequirementWaived))
Assuming you have navigation properties set up, this is much cleaner:
var HasBondorWaived=context.Allocations
.Where(a=>a.Permits.GUID.Equals(PermitGuid))
.Any(a=>a.Permits.BondRequirementWaived ||
a.Indemnities.Any(i=>i.IdemnityType.Description=="Performance Bonds" || i.IdemnityType.Description=="Payment Bonds"));
Kind of hard to see what you actually asking for, but I think that is what you want based on your question and without a clear entity model.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments