代码之家  ›  专栏  ›  技术社区  ›  Rodrigo Waltenberg

就像对实体的Linq

  •  6
  • Rodrigo Waltenberg  · 技术社区  · 14 年前

    我知道 .Contains() 方法确实喜欢 LIKE %therm% .StartsWith() 方法确实喜欢 LIKE therm% 以及 .EndsWith() LIKE %therm 但是。。。

    下面有办法吗 **Linq to Entities** ?

    SELECT * FROM [dbo].[Users] WHERE Name LIKE 'rodrigo%otavio%diniz%waltenberg'
    

    PS:我在用LINQ访问实体。不支持SQL

    3 回复  |  直到 14 年前
        1
  •  2
  •   Craig Stuntz    14 年前

    对, you can do this with ESQL /查询生成器语法:

    var matching = Context.Users.Where("it.Name LIKE 'rodrigo%otavio%diniz%waltenberg'");
    
        2
  •  2
  •   Community CDub    8 年前

    这应该能起到作用。

    from u in context.users
        where System.Data.Linq.SqlClient.SqlMethods.Like(
            u.Name, 
            "rodrigo%otavio%diniz%waltenberg")
        select u
    

    编辑:
    Linq SqlMethods.Like fails 建议您可以使用 Where 直接放在桌子上。

        3
  •  -1
  •   Terry C    14 年前

            RegularExpressions.Regex p 
                 = new RegularExpressions.Regex("rodrigo%otavio%diniz%waltenberg");
    
            using (DataContext.MyDataContext context = new MyDataContext())
            {
                var result = from u in context.users
                          where p.IsMatch(u.name)
                          select u;
            }