c# - need linq query to return only the last 100 results -


I am looking for a SQL Server database and apparently can handle this application. I am withdrawing the path of many results and need to reduce the number of records sent back to me and then tell the user that they have made too many choices.

What do I have here:

Private list & lt; Logs & gt; SearchLog () {try ({var model = new suburban Portrait Entity ()) {var qry = Logs in the model. Logs where logs. Logad time & gt; Datetime picture_start. Value & amp; Amp; Logs.LogDateTime & lt; Select DateTimePicker_End.Value Logs; Guid Tociniid; If (Guid.TryParse (textBox_TokenId.Text, outside the token)) {qry = qry.Where (x => x.TokenId == tokenie); } If (! String.EasnalOrcty (Textbox SECID.exe)) {qry = qry.Where (x => x.SessionId == textBox_SessionId.Text.ToLower ()); } If (! String.IsnellOnViewSpace (textboxcontenttext) {qry = qry.Where (x = & gt; x.Message.Contains (textBox_Contains.Text)); } If (checklistBoxieDisppleFilterGettySmche Czech (0)) {qry = qry.Where (x => x.IsWarning); } If (checklistbboxidfile filter.getitem check (1)) {qry = qry.Where (x => x.IsException); } Var sourceEnumList = new list & lt; String & gt; (); If (checkbox_webportal.checked) {sourceEnumList.Add ("WebPortal"); } If (checkBox_SubService.Checked) {sourceEnumList.Add ("SubService"); } If checked (checkbox recorder) {sourceEnumList.Add ("TruckRouting"); } If (checkBox_SuburbanHub.Checked) {sourceEnumList.Add ("SuburbanHub"); } If (sourceEnumList.Any ()) {qry = qry.Where (x => sourceEnumList.Contains (x.SourceEnum)); } Qry = qry.OrderByDescending (x => x.LogDateTime); Return qry.ToList (); }} Hold (Exception Pre) {MessageBox.Show ("Error:" + East Message); Return tap; }}

How do I get past 100 records and tell the user to tell them that their search needs to be refined?

Thank you!

You can use the method

  qry.Take the return (100) .toList ();  

If you do not sort your records by descending order , this will give you 100 records first. But I think that you already sort, so it should give you the right result. Anyway, if you want to delete OrderBy , then there is a line version to avoid confusion:

  return qry.OrderByDescending (x = & gt; x.LogDateTime) .ake (100) .toList ();  

Comments