【发布时间】:2014-03-14 10:57:50
【问题描述】:
我正在尝试在我的应用程序中创建一些过滤,用户将在其中单击单元格并根据该单元格值过滤表...到目前为止我有这个
int c = this.dataGridView1.CurrentCell.ColumnIndex;
int r = this.dataGridView1.CurrentCell.RowIndex;
string s = this.dataGridView1.Rows[r].Cells[c].Value.ToString();
string n = this.dataGridView1.Columns[c].DataPropertyName.ToString();
weblogEntities dbEntities = new weblogEntities();
this.Text = dbEntities.Database.Connection.ConnectionString.ToString();
var ds = dbEntities.tbl_weblog.Where(m => n == s).ToList();
dataGridView1.DataSource = ds;
但由于 lambda 表达式,我的过滤不起作用。有人可以指出我如何在我的 linq 中实际包含正确的 lambda 吗?
说明:
我想做的是(m=>m.field_name == value),其中m.field_name应该是n,在我执行过滤器之前我不知道那是什么,值参数是s。
【问题讨论】:
-
过滤器应该是什么?如果 n == s 你有它,那么你得到整个表,如果没有,那么你什么也得不到。您要过滤的列是什么?
-
我认为你需要比较“m”的一些属性。
-
你能用英文写下你的 where 子句应该是什么吗?因为不清楚你想要达到什么目的