简体   繁体   English

ASP.NET MVC 3 Linq 大写或小写数据库搜索

[英]ASP.NET MVC 3 Linq uppercase or lowercase database search

I need immediate help.我需要立即帮助。 ): and i know little english. ): 我懂一点英语。

ASP.NET MVC 3 Linq uppercase or lowercase contains search ASP.NET MVC 3 Linq 大写或小写包含搜索

Example:例子:

string metin="baris";

var IcerikAra = (from icerik in Context.dbDokumanEditor
join kategori in Context.dbDokumanKategori on 
icerik.KategoriID equals kategori.KategoriID
where icerik.Icerik.toLower().Contains(metin)
select new { 
KategoriID=kategori.
KategoriAd=kategori.KategoriAd
}).ToList();

Exception : StackTrace:异常堆栈跟踪:

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommandentityCommand, CommandBehavior behavior)
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Plus.Areas.DokumanEditor.Controllers.DokumanController.DokumanIcerikAramaBaslat(String metin)

Error Message: An error occurred while executing the command definition.错误消息:执行命令定义时发生错误。 See the inner exception for details.有关详细信息,请参阅内部异常。

thanks..谢谢..

Use String.Equals in your where clause在你的 where 子句中使用 String.Equals

where icerik.Icerik.Equals(metin,StringComparison.CurrentCultureIgnoreCase)

i solved as follows:我解决如下:

database datatype text -> old
database datatype nvarchar(MAX) -> new

var IcerikAra = (from icerik in Context.dbDokumanEditor
                 join kategori in Context.dbDokumanKategori on icerik.KategoriID equals kategori.KategoriID
where icerik.Icerik.ToLower().Contains(metin)
select new { 
     KategoriID=kategori.KategoriID,
     KategoriAd=kategori.KategoriAd
}).ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM