【发布时间】:2013-11-27 16:21:24
【问题描述】:
我正在尝试以下查询:
Return _context.companies _
.Where(Function(c) c.id.StartsWith(filterCompanyId)) _
.ToList()
但是因为id 是一个整数,所以它不起作用。我找到了this answer,这表明我可以使用
c.id.ToString().StartsWith ...
但这给了我以下错误:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
尝试使用时
.Where(Function(c) SqlFunctions.StringConvert(CDbl(c.id)).StartsWith("1"))
它不起作用。
有什么建议吗?
【问题讨论】:
-
所以如果
filterCompanyId是3,你想返回所有公司3、31、302等等。这样真的正确吗?这有意义吗? -
第二次尝试时收到什么错误消息?
-
是的,没错。用户对 ID 很熟悉,并且发现很容易将公司 ID 输入到框中以快速到达那里。
-
这应该有助于您转换为字符串:stackoverflow.com/q/1066760/87698
-
我找到了该帖子,但无法使用 VB.net/我的 EF 版本。
标签: vb.net linq-to-sql