ASP.NET-MVC Linq2Sql logic to get related items provided

I have a subcontracting table with a company field. On the company page, I don't want the company to be deleted if it is linked to an active subcontract. I am currently using the following expression to display the delete button. (Doesn't actually uninstall, just shuts down the company.)

<% if (item.company1.subcontracts.Count == 0) { %>

      

This works to exclude all companies that are attached to sub-contracts. However my subcontracting table also has an active_status field. I really want to be able to delete companies that are either not attached to a subcontract or attached to an inactive subcontract (active_status == 0).

+2


a source to share


2 answers


How about the following:

<% var subcontracts = item.company1.subcontracts;
if (subcontracts.Count == 0 || subcontracts.Any(x => x.active_status == 0)) { %>

      



This solves your problem if active_status is available via subcontracts

+2


a source


I may not understand you, but it seems that adding only OR to the IF should do the trick:



<% if (item.company1.subcontracts.Count == 0 || item.company1.active_status == 0) { %>

      

0


a source







All Articles