我需要帮助将SQL查询转换为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中执行此操作。感谢
答案 0 :(得分:1)
这已经解决了。感谢'CodeNotFound'获得此答案 https://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();
答案 1 :(得分:0)
试试这段代码
geopoints = args.getString("geoPoints");
答案 2 :(得分:0)
你应该用这种方法来删除布尔条件并减少代码
如果你需要检查Ef中的bool条件
1.真实条件 db.Customer.Where(p => p.customer_active).select(m => m).tolist(); 1.对于虚假条件 db.Customer.Where(p =>!p.customer_active).select(m => m).tolist();
仅供建议