返回IQueryable<T>与IEnumerable<T>?有什么区别?
IQueryable<Customer> custs = from c in db.Customers
where c.City == "<City>"
select c;
IEnumerable<Customer> custs = from c in db.Customers
where c.City == "<City>"
select c;
Run Code Online (Sandbox Code Playgroud)
两者都会延迟执行,何时应该优先于另一个?
我最近安装了SQL Server 2008,并选择了排序规则作为区分大小写.我想让它对整个实例不区分大小写(不适用于该实例中的数据库).如果我更改了排序规则,它是否会影响任何现有数据库?如果真是这样,那么是以哪种方式?
我想问一个关于 SQL Server 和 EF Core 的问题。数据库中的排序规则是Latin1_CI_AS,我想编写一个包含土耳其语字符的搜索查询。
在数据库中,'personnel'表中有一个名为“SEL?M”的记录。当我在 EF Core 中编写这样的查询时:
public async Task<IList<PersonnelGetDto>> Get(PersonnelGetPayload payload)
{
if (payload.Name != null)
query = query.Where(x => x.Name.Contains(payload.Name));
}
Run Code Online (Sandbox Code Playgroud)
如果我的搜索条件是“selim”,则列表为空。
我没有机会将数据库中的排序规则更改为土耳其语,因为我们的应用程序是多语言的。我认为其他语言会有问题。还是我错了?
我还写了字符串扩展名。但是,当将 LINQ 查询转换为 SQL 时,所有记录都会进入服务层,因为 LIKE 运算符未分配 WHERE 子句。在sql端运行这个条件非常重要。如果我把所有的数据集都拿到服务层去查询,会花费我很多。
当我在数据库中键入查询时,我可以解决这个问题:
SELECT * FROM Personnel WHERE Name LIKE 'selim' COLLATE Turkish_CI_AS
Run Code Online (Sandbox Code Playgroud)
我想如果我可以在 EF Core 上操作整理,我会解决这个问题。
c# sql-server case-insensitive entity-framework-core .net-core
我使用的是EF Core 3.1 + MySQL,并使用这种方法进行查询:
IQueryable<ApplicationUser> customers = from u in _context.Users where (u.Customer != null && u.IsActive) select u;
if (!String.IsNullOrEmpty(searchString))
{
customers = customers.Where(s => s.Email.Contains(searchString));
}
Run Code Online (Sandbox Code Playgroud)
我升级为使用 EF.Function.Like 以获得更好的性能:
if (!String.IsNullOrEmpty(searchString))
{
customers = customers.Where(x => EF.Functions.Like(x.Email, $"%{searchString}%"));
}
Run Code Online (Sandbox Code Playgroud)
但它是区分大小写的,如何使其不区分大小写呢?
c# ×3
sql-server ×2
.net-core ×1
collation ×1
ienumerable ×1
iqueryable ×1
linq ×1
linq-to-sql ×1