[英]How to perform linq search with spaces
I have a linq query that takes data from sql table . 我有一个linq查询,它从sql table获取数据。
In my database values written with the spaces after value like this : 在我的数据库中,在值后面加上空格,如下所示:
"Johny (and 5 spaces after that) ". “约翰尼(之后还有5个空格)”。 When i try to find "Johny" - (without spaces)query didn't work. 当我尝试找到“ Johny”时(无空格)查询不起作用。 But when i search "Johny " (after Johny - 5 spaces, it didnt show there) -it works. 但是当我搜索“ Johny”(在Johny之后-5个空格,它没有显示在那里)时,它起作用了。
because I can't change something in base , i didn't have permission for this . 因为我不能在基础上改变东西,所以我没有这个权限。
How can i make it work without spaces - changing only my query? 如何使它在没有空格的情况下工作-仅更改查询?
My code : 我的代码:
var fidn = (repository.users.Join(repository.usersLG,
post => post.pcod ,
meta => meta.pcod,
(post, meta) => new { Post = post, Meta = meta })
.Where(postAndMeta => postAndMeta.Post.fam_v == "Johny ").ToList())
.Select(x => new Final {
mcod = x.Post.mcod,
pcod = x.Post.pcod,
c_ogrn = x.Post.c_ogrn,
fam_v = x.Post.fam_v,
im_v = x.Post.im_v,
ot_v = x.Post.ot_v,
idGK = x.Meta.idGK });
Asp net web page c# entity framework ASP网页C#实体框架
Use Trim
: ( and also in this case consider changing to the query syntax, IMO more readable when it comes to joins ) 使用Trim
:( 并且在这种情况下,也可以考虑更改为查询语法,在涉及IMO时,IMO更具可读性 )
var fidn = from post in repository.users
join meta in repository.usersLG on post.pcod equals meta.pcod
where post.fam_v.Trim() == "Johny"
select new Final {
mcod = post.mcod,
pcod = post.pcod,
c_ogrn = post.c_ogrn,
fam_v = post.fam_v,
im_v = post.im_v,
ot_v = post.ot_v,
idGK = meta.idGK
};
Aslo have a look at C# naming conventions for the names of the properties in the Final
object Aslo看一下C#命名约定 ,以了解Final
对象中属性的名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.