如何在 Entity Framework CORE 中点赞(不完整的 .net)
How to do a LIKE in Entity Framework CORE (not full .net)
完整的 .net 框架中有 Entity Framework LIKE 的问答:
How to do SQL Like % in Linq?
Like Operator in Entity Framework?
例如:
from c in dc.Organization
where SqlMethods.Like(c.Boss, "%Jeremy%")
这在 EF Core 中不起作用:
The name SqlMethods does not exist in the current context.
那么如何使用 Entity Framework CORE 来点赞呢?
LIKE 函数已移至核心 EF.Functions
下:
from c in dc.Organization
where EF.Functions.Like(c.Boss, "%Jeremy%")
您可以使用 Contains
而不是 Like
函数
from c in dc.Organization
where c.Boss.Contains("Jeremy")
流畅版:
dc.Organization.Where(o => EF.Functions.Like(o.Boss, "%Jeremy%"));
完整的 .net 框架中有 Entity Framework LIKE 的问答:
How to do SQL Like % in Linq?
Like Operator in Entity Framework?
例如:
from c in dc.Organization
where SqlMethods.Like(c.Boss, "%Jeremy%")
这在 EF Core 中不起作用:
The name SqlMethods does not exist in the current context.
那么如何使用 Entity Framework CORE 来点赞呢?
LIKE 函数已移至核心 EF.Functions
下:
from c in dc.Organization
where EF.Functions.Like(c.Boss, "%Jeremy%")
您可以使用 Contains
Like
函数
from c in dc.Organization
where c.Boss.Contains("Jeremy")
流畅版:
dc.Organization.Where(o => EF.Functions.Like(o.Boss, "%Jeremy%"));