我在哪里可以找到包含T-SQL的IQueryable实现?

时间:2021-12-15 02:10:55

Everytime I do a:

每次我做一个:

journals = _context.Journals
            .Where(j => j.Name.Contains("foo"));

I feel the need to stop and write an extension on IQueryable that will make the Contains work. Is there one available already?

我觉得有必要停止并在IQueryable上写一个扩展来使Contains工作。有没有可用的?

1 个解决方案

#1


2  

Entity Framework supports contains on Strings and on Local lists.

实体框架支持包含字符串和本地列表。

From Docs:

来自Docs:

using (var context = new BloggingContext())
{
    var blogs = context.Blogs
        .Where(b => b.Url.Contains("dotnet"))
        .ToList();
}

Also this should work:

这应该工作:

List<string> urls = new List<string>() { "dotnet", "c#"};

using (var context = new BloggingContext())
{
    var blogs = context.Blogs
         .Where(b => urls.Contains(b.Url))
         .ToList();
}

#1


2  

Entity Framework supports contains on Strings and on Local lists.

实体框架支持包含字符串和本地列表。

From Docs:

来自Docs:

using (var context = new BloggingContext())
{
    var blogs = context.Blogs
        .Where(b => b.Url.Contains("dotnet"))
        .ToList();
}

Also this should work:

这应该工作:

List<string> urls = new List<string>() { "dotnet", "c#"};

using (var context = new BloggingContext())
{
    var blogs = context.Blogs
         .Where(b => urls.Contains(b.Url))
         .ToList();
}