entity framework and where with like [duplicate]

十年热恋 提交于 2019-12-05 20:02:45

If you want to do an equality comparison anyway, I suggest two ways:

db_user = db.CBR_User.FirstOrDefault(p => p.Codice_Fiscale.Equals(code, StringComparison.OrdinalIgnoreCase));

Or

db_user = db.CBR_User.FirstOrDefault(p => p.Codice_Fiscale.ToUpper() == code.ToUpper());

If you don't want that, you can use StartsWith, Contains, etc, with the parameter StringComparison.OrdinalIgnoreCase.

You can use Contains():

db_user = db.CBR_User.FirstOrDefault(p => p.Codice_Fiscale.Contains(code));
computercarguy

I know this is an old topic, but to expand on what Kristof Claes was saying,

db_user = db.CBR_User.FirstOrDefault(p => p.Codice_Fiscale.ToUpper().Contains(code.ToUpper()));

if you use the ToUpper option, it will act as if it is a case insensitive search. You could use ToLower to do the same thing, in case you have that penchant.

In LINQ To Entity you have functions like StartsWith, EndsWith and Contains that you can use instead like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!