将 sql 转换为 linq 示例
我有一个 sql 语句,但我无法让它在 linq 中工作。有人可以告诉我如何将以下 sql 语句编写为 linq 吗?
SELECT * FROM mobileApplication
LEFT JOIN videoMobile ON mobileApplication.id = videoMobile.mobileApplicationId
AND videoMobile.videoId = 257
这是一个左连接,右表上有一个 where 语句。它可以在 sql server 2005 中运行,但我想用 linq 编写它。
I've got a sql statement, but I can't get it working in linq. Can someone show me how I can write the following sql statement as linq?
SELECT * FROM mobileApplication
LEFT JOIN videoMobile ON mobileApplication.id = videoMobile.mobileApplicationId
AND videoMobile.videoId = 257
It's a left join with a where statement on the right table. It works in sql server 2005, but I'd like to write it in linq.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我没有验证语法,但试试这个......
I didn't verify the syntax, but try this...
有一种产品可以为您做到这一点。我发现它非常有用。产品名称为Linqer。它不是免费的,但也不贵,并且提供 30 天的试用期。我发现很少有它无法转换的查询。它对我来说效果很好。
There is a product that will do this for you. I have found it very useful. The product name is Linqer. It is not free, but not expensive, and offers a 30 day trial. I have found very few queries it is not able to convert. It has worked well for me.
它类似于:
如果键为空,则默认为键,并在连接条件上使用匿名对象将 257 合并到连接中。
我很确定对 257 使用 where 子句会达到相同的结果......
Its something like:
The keys being the default if empty and using anonymous objects on the join criteria to incorporate 257 into the join.
I am pretty sure that using a where clause for the 257 will achieve the same result though...
尝试这样的:
请参阅此处:
http: //msdn.microsoft.com/en-us/library/bb397676%28v=VS.100%29.aspx
http://msdn.microsoft.com/en-us/magazine/cc163400.aspx
Try some like this:
See here:
http://msdn.microsoft.com/en-us/library/bb397676%28v=VS.100%29.aspx
http://msdn.microsoft.com/en-us/magazine/cc163400.aspx