Lambda Where Contains不区分大小写,但是linq中的关键字区分大小写

时间:2019-06-13 02:00:28

标签: c# entity-framework linq lambda

我在数据库中有一列post_title,其名称为COLLATE,名称为SQL_Latin1_General_CP1_CI_AI。 我有两个Lambda和Linq查询:

post = db.postRepository.AllPosts()
                    .Where(m => m.status)
                    .OrderByDescending(m => m.create_date)
                    .Select(m => new lstPostViewModel
                    {
                        post_id = m.post_id,
                        post_title = m.post_title,
                        post_teaser = m.post_teaser,
                        ViewCount = m.ViewCount,
                        AvatarImage = m.AvatarImage,
                        create_date = m.create_date
                    }
                    ).ToPagedList(pageIndex, pageSize);

上面的代码块返回不区分大小写的数据

但是,如果我这样写linq,则数据返回区分大小写:

using (DVCPContext conn = db.Context)
                    {
                        var query = (
                            from z in taglist
                            join a in conn.Tbl_Tags on z.TagID equals a.TagID
                            // instance from navigation property
                            from b in a.Tbl_POST
                            // join to bring useful data
                            join c in conn.Tbl_POST on b.post_id equals c.post_id
                            where b.status == true
                            where b.dynasty == model.Dynasty.ToString()
                            where b.post_title.Contains(model.title)

                            orderby c.post_title.Contains(model.title)
                            select new lstPostViewModel
                            {
                                c.post_id,
                                c.post_title,
                                c.post_teaser,
                                c.ViewCount,
                                c.AvatarImage,
                                c.create_date
                            });
                        post = query.ToPagedList(pageIndex, pageSize);
                    }

如果我将上面的代码块替换为:

where b.post_title.ToLower().Contains(model.title.ToLower())

效果很好。但是我不知道性能是否降低了?

0 个答案:

没有答案