linq 到实体 orderby
如何将此查询转换为具有实体框架的实体的 linq:
SELECT customer_id,
customer_name,
customer_code
FROM dbo.V_STF_CUSTOMER
WHERE company_id=@company_id AND
ORDER BY CASE
WHEN ISNUMERIC(customer_name)=1 THEN 1
ELSE 0
END,
customer_name
我有这个:
return CUstomers.GetQuery().
Where(x => x.CompanyId == companyId).
OrderBy(??This is my problem??);
我不知道如何翻译 orderby。有什么想法吗?
How can I convert this query to linq to entities with entity framework:
SELECT customer_id,
customer_name,
customer_code
FROM dbo.V_STF_CUSTOMER
WHERE company_id=@company_id AND
ORDER BY CASE
WHEN ISNUMERIC(customer_name)=1 THEN 1
ELSE 0
END,
customer_name
I have this:
return CUstomers.GetQuery().
Where(x => x.CompanyId == companyId).
OrderBy(??This is my problem??);
I don't know how to translate the orderby. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在查询中使用 SqlFunctions.IsNumeric 来映射到 Sql Server 中的 IsNumeric。
大致如下:
You can use SqlFunctions.IsNumeric in your query to map to IsNumeric in Sql Server.
Something along the lines of:
首先,我认为 SQL 查询有问题,
为什么添加
AND
?您可以通过使用
First I think there something wrong with the SQL query in
why you added
AND
?you can achieve ISNUMERIC in Entity Framewwork only (not linq to sql) by using SqlFunctions.IsNumeric