linq

Linq with optional WHERE options

一个人想着一个人 提交于 2021-01-02 08:12:10
问题 I have a .Net function that accepts 3 parameters, all optional. Something like this: public List<MyObject> Search(string colour, string size, string name) { var result = (from c in MyTable where .... select c).ToList(); } My question is, what is the best way to do the where part. Would the best be to create dynamic linq? What's the best pattern, within linq, to have optional where parameters? So, in SQL, something like this: SELECT * FROM MyTable WHERE (@colour <> '' AND colour = @colour) AND

How to run complex query with Any() inside Any(). MongoDB Driver C#

我的未来我决定 提交于 2021-01-02 00:35:48
问题 I haven't been able to perform a complex query with an Any() inside an Any(), using MongoDB C# Driver.. I have this C# models (equivalent to the mongo database models): [BsonCollection("alert_evaluations")] public class AlertEvaluation : Document { public ICollection<EvaluationResult> EvaluationResults { get; set; } public string EvaluationStatus { get; set; } public DateTime EvaluatedAt { get; set; } } public class EvaluationResult { public ICollection<EvaluatedLabel> EvaluatedLabels { get;

How to run complex query with Any() inside Any(). MongoDB Driver C#

若如初见. 提交于 2021-01-02 00:33:51
问题 I haven't been able to perform a complex query with an Any() inside an Any(), using MongoDB C# Driver.. I have this C# models (equivalent to the mongo database models): [BsonCollection("alert_evaluations")] public class AlertEvaluation : Document { public ICollection<EvaluationResult> EvaluationResults { get; set; } public string EvaluationStatus { get; set; } public DateTime EvaluatedAt { get; set; } } public class EvaluationResult { public ICollection<EvaluatedLabel> EvaluatedLabels { get;

How to run complex query with Any() inside Any(). MongoDB Driver C#

安稳与你 提交于 2021-01-02 00:33:41
问题 I haven't been able to perform a complex query with an Any() inside an Any(), using MongoDB C# Driver.. I have this C# models (equivalent to the mongo database models): [BsonCollection("alert_evaluations")] public class AlertEvaluation : Document { public ICollection<EvaluationResult> EvaluationResults { get; set; } public string EvaluationStatus { get; set; } public DateTime EvaluatedAt { get; set; } } public class EvaluationResult { public ICollection<EvaluatedLabel> EvaluatedLabels { get;

Subquery in Where Clause of LINQ statement

╄→гoц情女王★ 提交于 2021-01-01 09:57:13
问题 So I tried to follow this example to have a sub-query in the where clause of this LINQ query. var innerquery = from app in context.applications select new { app.app_id }; IEnumerable<postDatedCheque> _entityList = context.postDatedCheques .Where(e => innerquery.Contains(e.appSancAdvice.application.app_id)); The objective was to select those records from postDatedCheques that have app_id in applications table. But I am getting following erros inside the where clause: Delegate 'System.Func'

Strong-typed Linq to construct OData query options

荒凉一梦 提交于 2021-01-01 07:41:31
问题 Assume the following example that demonstrates how to perform read operation using HttpClient: using (var client = new HttpClient()) { client.BaseAddress = webUri; client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var requestUrl = "/api/products?$filter=(Category eq 'Cars')"; var response = await client.GetAsync(requestUrl); if (response.IsSuccessStatusCode) { var products = await response.Content

Remove duplicate records using LINQ [duplicate]

十年热恋 提交于 2021-01-01 03:38:56
问题 This question already has answers here : LINQ: Distinct values (7 answers) Closed 5 years ago . I want to use linq to object to remove duplicate records. I want that final list will contain unique records with the latest Date. I have the following list AId BId C(date) **1 2 24/5/2015** 3 6 24/5/2015 **1 2 23/5/2015** (Need To Remove) I want to remove record 3. Any Advise? 回答1: You can use GroupBy and then Select with OrderByDescending to order the dates. public class Item { public int Aid

Remove duplicate records using LINQ [duplicate]

瘦欲@ 提交于 2021-01-01 03:34:28
问题 This question already has answers here : LINQ: Distinct values (7 answers) Closed 5 years ago . I want to use linq to object to remove duplicate records. I want that final list will contain unique records with the latest Date. I have the following list AId BId C(date) **1 2 24/5/2015** 3 6 24/5/2015 **1 2 23/5/2015** (Need To Remove) I want to remove record 3. Any Advise? 回答1: You can use GroupBy and then Select with OrderByDescending to order the dates. public class Item { public int Aid

Union Two Linq Queries

你。 提交于 2020-12-31 14:56:25
问题 I have two LinqToSql queries that return result sets: var grResults = (from g in ctx.GeneralRequests join rt in ctx.RequestTypes on g.RequestTypeId equals rt.RequestTypeId join sub in ctx.Logins on g.SubmitterStaffId equals sub.LoginId join onb in ctx.Logins on g.OnBehalfOfStaffId equals onb.LoginId where sub.GadId == gadId select new { Status = "Submitted", RequestId = g.GeneralRequestId, Submitter = sub.UserName, OnBehalf = (onb == null ? string.Empty : onb.UserName), RequestType = (rt ==

ASPxGridView1用法<->

不羁岁月 提交于 2020-12-31 09:23:12
后台帮定代码: using System; using System.Collections.Generic; using System.Linq;using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Datagrid(); } private void Datagrid() { DataTable data = DB.FillDataTable_Pro("select top 40 * from bi_t_item_info"); this.ASPxGridView1.DataSource = data; this.ASPxGridView1.DataBind(); } //***事件 protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) DB.ExecuteScalar(string