本文介绍了将SQL查询转换为LINQ-to-SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助将SQL查询从LINQ转换为SQL

I need help converting SQL query to LINQ to SQL

select top 5 customer_id, customer_name, product_id
from Customer
Join Product on product_id = product_id
where (customer_active = 'TRUE')
order by checksum(newid())

如何在LINQ to SQL中做到这一点.谢谢

How can I do that in LINQ to SQL. Thanks

推荐答案

此问题已解决.感谢"CodeNotFound"提供此答案 https://stackoverflow.com/a/43850748/1655774

This was solved. Thanks to 'CodeNotFound' for this answerhttps://stackoverflow.com/a/43850748/1655774

db.Customer.Where(p => p.customer_active == true).Select(p => new CustomerViewModel
    {
         Customer_id= p.customer_id,
         Customer_name = p.customer_name,
         Product_id = p.Product.product_id
    }).OrderBy(c => SqlFunctions.Checksum(Guid.NewGuid())).Take(5).ToList();

这篇关于将SQL查询转换为LINQ-to-SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 21:51