使用实体框架过滤datagridview [英] Filter a datagridview using entities framework

查看:78
本文介绍了使用实体框架过滤datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我刚刚找到了实体的linq。我决定在我的程序中使用它。



我有一个带有Sql server 2014的数据库。我在Ado.net实体数据模型的帮助下导入了我的数据库。



在那之前一切都很好,我创建了一个上下文,我在绑定源上绑定它,绑定源绑定到我的datagridview。



问题是当我在bindingsource.filter的帮助下过滤我的datagridview时,没有任何反应。



我做了一个错误的地方?或者它是一个不允许过滤的列表?



否则,在实体框架的帮助下,我是否可以使用另一种方式来过滤一个datagridview?



ps:completeInventory是一个存储过程,可以在多个表中选择多个字段。



我的尝试:



Hi guys,

I just found linq to entities. I decided to use it in my program.

I have a database with Sql server 2014. I imported my database with the help of "Ado.net entity data model".

Until then everything is fine, I created a context and I binded it on a bindingsource and the bindingsource is binded to my datagridview.

The problem is that when I come to filter my datagridview with the help of bindingsource.filter, nothing happens.

Did I make a mistake somewhere? Or is it the fact that it is a list that does not allow to filter?

Otherwise, would there be another way I could use with the help of entity framework to filter a datagridview?

ps: completeInventory is a stored procedure that select multiple field in multiple table.

What I have tried:

  bindingsource.DataSource = entitiesCOOP.completeInventory.ToList()
dgv.DataSource = bindingsource

bindingsource.Filter = String.Format("description LIKE '" & txt_description.Text & "'")
 dgv.Refresh()

推荐答案

你的过滤器无关与实体框架。你正在使用的是正常的日常BindingSource过滤。



你的过滤器不起作用可能是因为过滤器表达式中没有通配符:

Your "filter" has nothing to do with Entity Framework. What you're using is normal everyday BindingSource Filtering.

Your filter doesn't work probably because you have no wildcards in the filter expression:
description LIKE '%something%'



将在描述中的任何位置找到包含something的描述的任何记录字段。



删除开头或尾随'%'符号,您可以过滤以搜索词开头或结尾的描述。


will find any record with a description that contains 'something' anywhere in the description field.

Drop the beginning or trailing '%' sign and you can filter on descriptions beginning with or ending with the search word.


这篇关于使用实体框架过滤datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆