A where statement on the property "Description" was yielding no results so I tried creating a where statement on a different field of the same field type "EntityName. The where statement on "EntityName" works as expected; the where statement on "Description" yields no results.
I've tried copy and pasting the "Description" property name from model to controller to avoid discrepancy in spelling / typos between the two.
var variableName = from s in _context.Financial // Toggling between two below...
where s.Description == "Speedway" // <- Yields no results
//where s.EntityName == "Discover" // <- Yields correct results
select s;
Controller
// GET: Financial
public async Task<IActionResult> IndexRecurring(string sortOrder, string currentFilter, string searchString, int? pageNumber)
{
ViewData["CurrentSort"] = sortOrder;
ViewData["dateSort"] = String.IsNullOrEmpty(sortOrder) ? "dateDesc" : ""; // These are ternary statements (re: ternary conditional operators).
ViewData["entitySort"] = sortOrder == "entity" ? "entityDesc" : "entity";
ViewData["descriptionSort"] = sortOrder == "description" ? "descriptionDesc" : "description";
if (searchString != null)
{
pageNumber = 1;
}
else
{
searchString = currentFilter;
}
ViewData["CurrentFilter"] = searchString; // Toggling between two below
var variableName = from s in _context.Financial
where s.Description == "Speedway" // <- Yields no results
//where s.EntityName == "Discover" // <- Yields correct results
select s;
if (!String.IsNullOrEmpty(searchString))
{
variableName = variableName.Where(s => s.EntityName!.Contains(searchString)
|| s.AccountOwner!.Contains(searchString)
|| s.AccountIdentifier!.Contains(searchString)
|| s.Description!.Contains(searchString)
|| s.Category!.Contains(searchString)
|| s.Amount!.GetValueOrDefault().ToString().Contains(searchString) // int property type - requires conversion to string for search
//|| s.DateTransaction!.GetValueOrDefault().ToString().Contains(searchString)
//|| s.DatePost!.GetValueOrDefault().ToString().Contains(searchString)
);
}
switch (sortOrder)
{
default: // "fall-through case" in the switch statement
variableName = variableName.OrderByDescending(s => s.DatePost);
break;
case "dateDesc":
variableName = variableName.OrderBy(s => s.DatePost);
break;
// _________________________________
case "entity":
variableName = variableName.OrderBy(s => s.EntityName);
break;
case "entityDesc":
variableName = variableName.OrderByDescending(s => s.EntityName);
break;
// _________________________________
case "description":
variableName = variableName.OrderBy(s => s.Description);
break;
case "descriptionDesc":
variableName = variableName.OrderByDescending(s => s.Description);
break;
}
int pageSize = 14;
return View(await PaginatedList<Financial>.CreateAsync(variableName.AsNoTracking(), pageNumber ?? 1, pageSize));
}
Model
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
namespace Dashboard.Models
{
public class Financial
{
public int Id { get; set; }
public string? EntityType { get; set; }
public string? EntityName { get; set; }
public string? AccountType { get; set; }
public string? AccountOwner { get; set; }
public string? AccountAccess { get; set; }
public string? AccountDescription { get; set; }
public string? AccountIdentifier { get; set; }
// ___________________________________
[Display(Name = "Details")]
public string? TransactionType1 { get; set; } // "Details"
[Display(Name = "Transaction")]
[DataType(DataType.Date)]
public DateTime? DateTransaction { get; set; } // [DataType(DataType.Date)] = only date, no time information
[Display(Name = "Post")]
[DataType(DataType.Date)]
public DateTime? DatePost { get; set; }
public string? Description { get; set; }
[Column(TypeName = "decimal(18, 2)")]
public int? Amount { get; set; }
[Display(Name = "Type")]
public string? TransactionType2 { get; set; } // "Type"
[Column(TypeName = "decimal(18, 2)")]
public int? Balance { get; set; }
public string? Category { get; set; }
[Display(Name = "Renewal")]
[DataType(DataType.Date)]
public DateTime? DateRenewal { get; set; }
// ___________________________________
public int? CheckOrSlipNumber { get; set; }
public string? Memo { get; set; }
// ___________________________________
public string? Category1a { get; set; }
public string? Category1b { get; set; }
public string? Category1c { get; set; }
public string? Category2a { get; set; }
public string? Category2b { get; set; }
public string? Category2c { get; set; }
public string? AccountType1 { get; set; }
public string? AccountType2 { get; set; }
public string? AccountType3 { get; set; }
public string? Tag { get; set; }
public string? Flag { get; set; }
public bool? Private { get; set; }
}
}
View
@model PaginatedList<Dashboard.Models.Financial>
@*************** Pre-Pagination ******************@
@*@model IEnumerable<Project01Name.Models.Class01Name>*@
@************* Pre-Pagination (end) **************@
@{
ViewData["Recurring"] = "Recurring";
}
<h1>Recurring</h1>
<p>
<a asp-action="Create">Create New</a>
</p>
<form asp-action="IndexRecurring" method="get">
<div class="form-actions no-color">
<p>
Find by name: <input type="text" name="SearchString" value="@ViewData["CurrentFilter"]" />
<input type="submit" value="Search" class="btn btn-default" />
<a asp-action="IndexRecurring">Back to Full List</a>
</p>
</div>
</form>
<table class="table">
<thead>
<tr>
<th>
<a asp-action="IndexRecurring" asp-route-sortOrder="@ViewData["dateSort"]" asp-route-currentFilter="@ViewData["CurrentFilter"]">Post</a>
</th>
<th>
<a asp-action="IndexRecurring" asp-route-sortOrder="@ViewData["entitySort"]" asp-route-currentFilter="@ViewData["CurrentFilter"]">Name</a>
</th>
<th>
Owner
</th>
<th>
Type
</th>
<th>
ID
</th>
<th>
<a asp-action="IndexRecurring" asp-route-sortOrder="@ViewData["descriptionSort"]" asp-route-currentFilter="@ViewData["CurrentFilter"]">Description</a>
</th>
<th>
Amount
</th>
<th>
Category
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.DatePost)
</td>
<td>
@Html.DisplayFor(modelItem => item.EntityName)
</td>
<td>
@Html.DisplayFor(modelItem => item.AccountOwner)
</td>
<td>
@Html.DisplayFor(modelItem => item.AccountType)
</td>
<td>
@Html.DisplayFor(modelItem => item.AccountIdentifier)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Amount)
</td>
<td>
@Html.DisplayFor(modelItem => item.Category)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
</td>
</tr>
}
</tbody>
</table>
@{
var prevDisabled = !Model.HasPreviousPage ? "disabled" : "";
var nextDisabled = !Model.HasNextPage ? "disabled" : "";
}
<a asp-action="IndexRecurring"
asp-route-sortOrder="@ViewData["CurrentSort"]"
asp-route-pageNumber="@(Model.PageIndex - 1)"
asp-route-currentFilter="@ViewData["CurrentFilter"]"
class="btn btn-default @prevDisabled">
Previous
</a>
<a asp-action="IndexRecurring"
asp-route-sortOrder="@ViewData["CurrentSort"]"
asp-route-pageNumber="@(Model.PageIndex + 1)"
asp-route-currentFilter="@ViewData["CurrentFilter"]"
class="btn btn-default @nextDisabled">
Next
</a>
MSSMS

Sample Data
