开发者

ASP.NET-MVC Linq2Sql logic to get linked items on condition

开发者 https://www.devze.com 2022-12-30 17:00 出处:网络
I have a 开发者_运维问答subcontract table with a company field.On the company page, I do not want the company to be able to be deleted if it is attached to an active subcontract.I am currently using t

I have a 开发者_运维问答subcontract table with a company field. On the company page, I do not want the company to be able to be deleted if it is attached to an active subcontract. I am currently using the following expression to display the delete button. (Doesn't actually delete, just sets company to inactive.)

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

This works for excluding all companies which are attached to subcontracts. However, my subcontract table also has an active_status field. What I really want is to be able to delete companies which are either not attached to a subcontract or are attached to an inactive subcontract (active_status == 0).


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 the active_status is accessible through subcontracts


Maybe I am misunderstanding you, but it seems adding just an OR to the IF should do the trick:

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

精彩评论

暂无评论...
验证码 换一张
取 消