Enum Condition in Linq Query in C#
<p>I want to add <code>Enum</code> Condition in Linq Query even if Enum datamember is null or empty</p>

<p>I had added <code>ALL</code> in model for Filter purpose so that if user select ALL then all data should be displayed </p>

<p><a href="https://i.stack.imgur.com/li7In.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/li7In.png" alt="Web Screen"></a></p>

<p>Data Model : </p>

<pre><code>    public partial class AuditTable
    {
        public int ID { get; set; }
        public int CompanyId { get; set; }
        public int KeyFieldID { get; set; }
        public System.DateTime DateTimeStamp { get; set; }
        public EntityType DataModel { get; set; }
        public string ValueBefore { get; set; }
        public string ValueAfter { get; set; }
        public string Changes { get; set; }
        public AuditActionType AuditActionTypeENUM { get; set; }

        public int EmployeeId { get; set; }
        public string EmployeeCode { get; set; }
        public string Remarks { get; set; }
        public string IPAddress { get; set; }
        public string UserName { get; set; }
    }
 public enum AuditActionType
    {
        All = 1,
        Create,
        Update,
        Delete
    }

    public enum EntityType
    {
        All = 1,
        BasicDetails,
        EmployeeDetails,
        PersonalDetails                
    }
</code></pre>

<p>Below code is working fine but had to repeat same query 4 times. I want to combine below query into one</p>

<pre><code>if (eType == EntityType.All)
 if (aType == AuditActionType.All)
  AuditTrail = ent.tblAuditTable.Where(s =&gt; s.KeyFieldID == ID &amp;&amp; s.EmployeeCode.Contains(code) &amp;&amp; s.UserName.Contains(username)).OrderByDescending(s =&gt; s.DateTimeStamp).ToList(); 
 else
  AuditTrail = ent.tblAuditTable.Where(s =&gt; s.KeyFieldID == ID &amp;&amp; s.AuditActionTypeENUM == aType &amp;&amp; s.EmployeeCode.Contains(code) &amp;&amp; s.UserName.Contains(username)).OrderByDescending(s =&gt; s.DateTimeStamp).ToList(); 
else
if (aType == AuditActionType.All)
 AuditTrail = ent.tblAuditTable.Where(s =&gt; s.KeyFieldID == ID &amp;&amp; s.DataModel == eType &amp;&amp; s.EmployeeCode.Contains(code) &amp;&amp; s.UserName.Contains(username)).OrderByDescending(s =&gt; s.DateTimeStamp).ToList();
else
 AuditTrail = ent.tblAuditTable.Where(s =&gt; s.KeyFieldID == ID &amp;&amp; s.AuditActionTypeENUM == aType &amp;&amp; s.DataModel == eType &amp;&amp; s.EmployeeCode.Contains(code) &amp;&amp; s.UserName.Contains(username)).OrderByDescending(s =&gt; s.DateTimeStamp).ToList(); 
</code></pre>