代码之家  ›  专栏  ›  技术社区  ›  Curtis White

不支持Linq To Sql方法?

  •  0
  • Curtis White  · 技术社区  · 14 年前

    var myUsers = from u in table
                  where u.UniqueIdentifierId == MyClass.GetCurrentUserId()
                  select u;
    

    这将引发自定义函数不支持的方法错误。我重新编码了

    string guid = MyClass.GetCurrentUserId().ToString();
    
    where u.UniqueIdentifierId.ToString() == guid
    

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

    您不能在查询中调用它,因为linqtosql不能转换它。它尝试在一个SQL调用中对此进行转换。您必须在LINQ查询之外调用此方法,如下所示:

    var guid = MyClass.GetCurrentUserId();
    
    var myUsers = 
        from u in table
        where u.UniqueIdentifierId == guid
        select u;
    
        2
  •  1
  •   Nix    14 年前

    你试过了吗?

    var myUsers = from u in table
              where u.UniqueIdentifierId == MyClass.GetCurrentUserId().ToString()
              select u;