开发者

Problem passing in Func as parameter to Where clause

开发者 https://www.devze.com 2022-12-30 13:09 出处:网络
I have this simple 2 lines of following code. It compiles fine but never return results in the datagridview开发者_如何学C. If I change func to p=> p.PTNT_FIRST_NAME.StartsWith(this.textBox1.Text),

I have this simple 2 lines of following code. It compiles fine but never return results in the datagridview开发者_如何学C. If I change func to p=> p.PTNT_FIRST_NAME.StartsWith(this.textBox1.Text), it works just fine. What's the problem here?

Func<PATIENT, bool> func = (PATIENT p) => p.PTNT_FIRST_NAME.StartsWith(this.textBox1.Text);
this.dataGridView1.DataSource = dataContext.PATIENTs.Where<PATIENT>(func).Select(q => q);


Change Func<PATIENT, bool> to Expression<Func<PATIENT, bool>>.


Try this:

Expression<Func<PATIENT, bool>> func = (PATIENT p) => p.PTNT_FIRST_NAME.StartsWith(this.textBox1.Text);
0

精彩评论

暂无评论...
验证码 换一张
取 消