C# where语句查询时的多参数Func
Posted 吃瓜青蛙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# where语句查询时的多参数Func相关的知识,希望对你有一定的参考价值。
适用场景:查询条件为有限个且动态的,查询条件有值时考虑,无值时不考虑。
gitee地址:https://gitee.com/zhangyf6548/winfrom-scaffold
首先winform界面方便调试
namespace WinFormsApp1
{
partial class LandDataForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.label1 = new System.Windows.Forms.Label();
this.btn_Ok = new System.Windows.Forms.Button();
this.btn_Cancel = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.btnQuery = new System.Windows.Forms.Button();
this.txtNum = new System.Windows.Forms.TextBox();
this.txtName = new System.Windows.Forms.TextBox();
this.txtLocation = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(26, 15);
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(54, 20);
this.label1.TabIndex = 0;
this.label1.Text = "编号:";
//
// btn_Ok
//
this.btn_Ok.Location = new System.Drawing.Point(351, 487);
this.btn_Ok.Margin = new System.Windows.Forms.Padding(2, 4, 2, 4);
this.btn_Ok.Name = "btn_Ok";
this.btn_Ok.Size = new System.Drawing.Size(96, 31);
this.btn_Ok.TabIndex = 5;
this.btn_Ok.Text = "确定";
this.btn_Ok.UseVisualStyleBackColor = true;
this.btn_Ok.Click += new System.EventHandler(this.btn_Ok_Click);
//
// btn_Cancel
//
this.btn_Cancel.Location = new System.Drawing.Point(486, 487);
this.btn_Cancel.Margin = new System.Windows.Forms.Padding(2, 4, 2, 4);
this.btn_Cancel.Name = "btn_Cancel";
this.btn_Cancel.Size = new System.Drawing.Size(96, 31);
this.btn_Cancel.TabIndex = 6;
this.btn_Cancel.Text = "取消";
this.btn_Cancel.UseVisualStyleBackColor = true;
this.btn_Cancel.Click += new System.EventHandler(this.btn_Cancel_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// dataGridView1
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.AllowUserToResizeColumns = false;
this.dataGridView1.AllowUserToResizeRows = false;
this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
this.dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.dataGridView1.ColumnHeadersHeight = 29;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column4,
this.Column2,
this.Column3});
this.dataGridView1.Location = new System.Drawing.Point(30, 58);
this.dataGridView1.Margin = new System.Windows.Forms.Padding(2, 4, 2, 4);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersVisible = false;
this.dataGridView1.RowHeadersWidth = 51;
this.dataGridView1.RowTemplate.Height = 27;
this.dataGridView1.Size = new System.Drawing.Size(876, 383);
this.dataGridView1.TabIndex = 8;
this.dataGridView1.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dataGridView1_RowPostPaint);
//
// Column1
//
this.Column1.DataPropertyName = "index";
this.Column1.HeaderText = "序号";
this.Column1.MinimumWidth = 6;
this.Column1.Name = "Column1";
this.Column1.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.Column1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.Column1.Width = 125;
//
// Column4
//
this.Column4.DataPropertyName = "num";
this.Column4.HeaderText = "编号";
this.Column4.MinimumWidth = 6;
this.Column4.Name = "Column4";
this.Column4.Width = 190;
//
// Column2
//
this.Column2.DataPropertyName = "name";
this.Column2.HeaderText = "名称";
this.Column2.MinimumWidth = 6;
this.Column2.Name = "Column2";
this.Column2.Width = 200;
//
// Column3
//
this.Column3.DataPropertyName = "location";
this.Column3.HeaderText = "位置";
this.Column3.MinimumWidth = 6;
this.Column3.Name = "Column3";
this.Column3.Width = 300;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(208, 15);
this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 20);
this.label2.TabIndex = 9;
this.label2.Text = "名称:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(456, 15);
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(54, 20);
this.label3.TabIndex = 10;
this.label3.Text = "位置:";
//
// btnQuery
//
this.btnQuery.Location = new System.Drawing.Point(810, 13);
this.btnQuery.Margin = new System.Windows.Forms.Padding(2, 4, 2, 4);
this.btnQuery.Name = "btnQuery";
this.btnQuery.Size = new System.Drawing.Size(96, 31);
this.btnQuery.TabIndex = 11;
this.btnQuery.Text = "查询";
this.btnQuery.UseVisualStyleBackColor = true;
this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
//
// txtNum
//
this.txtNum.Location = new System.Drawing.Point(85, 13);
this.txtNum.Name = "txtNum";
this.txtNum.Size = new System.Drawing.Size(100, 27);
this.txtNum.TabIndex = 12;
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(277, 13);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(152, 27);
this.txtName.TabIndex = 13;
//
// txtLocation
//
this.txtLocation.Location = new System.Drawing.Point(526, 13);
this.txtLocation.Name = "txtLocation";
this.txtLocation.Size = new System.Drawing.Size(170, 27);
this.txtLocation.TabIndex = 14;
//
// LandDataForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(928, 540);
this.Controls.Add(this.txtLocation);
this.Controls.Add(this.txtName);
this.Controls.Add(this.txtNum);
this.Controls.Add(this.btnQuery);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.dataGridView1);
this.Controls.Add(this.btn_Cancel);
this.Controls.Add(this.btn_Ok);
this.Controls.Add(<以上是关于C# where语句查询时的多参数Func的主要内容,如果未能解决你的问题,请参考以下文章
c# linq语句的Expression<Func<TEntity,bool>>怎么传进参数
Mybatis -- 动态Sql概述动态Sql之<if>(包含<where>)动态Sql之<foreach>sql片段抽取