实体框架的部分文本搜索 [英] partial text search for Entity Framework

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

问题描述

大家好,

我有4种不同类型的列,例如int,date,string,decimal
我想按所有这些数据类型进行搜索,并根据搜索结果将结果显示到网格视图

我的代码示例将使用int值,问题是只有输入精确值后它才起作用
我要部分文本搜索,怎么办?


Hi all,

i have 4 columns of different types ,like int,date,string,decimal
i want to search by all these data types and based on the search i will display result to grid view

example of my code which will take the int value ,the problem is its only working when exact value is entered
i want partial text search ,how can i do?


Int32 sid = Convert.ToInt32(id.Text);
        testingModel.testingEntities te = new testingModel.testingEntities();
        if (id.Text != "")
        {
            var disp = from i in te.alltypes
                       where i.@int.Equals(sid)
                       select i;
            GridView1.DataSource = disp;
            GridView1.DataBind();
        }

推荐答案

大家好,

在有条件的情况下,使用以下代码

字符串sid = id.Text;//文本框名称

其中SqlFunctions.StringConvert((Decimal)i.列名).包含(sid)
hi all,

in where condition use the below code

String sid = id.Text;//textbox name

where SqlFunctions.StringConvert((Decimal)i.columnname).Contains(sid)


如果要搜索部分数值匹配,您显然需要将int转换为字符串,并使用Contains进行比较.

我没有要测试的模型设置,但应该类似于

If you want to search for a partial numeric match you will need to obviously convert the int to a string and use Contains for the comparison.

I don''t have a model setup to test but it should be something like

var disp = from i in te.alltypes
            where i.ToString().Contains(sid)
            select i;


这篇关于实体框架的部分文本搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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