本文介绍了如何将sql转换为linq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 选择 cl.clientid,clad.address1,clad.address2 来自客户端cl join ClientAddress clad on cl.id = clad.clientguid 其中 clad.Address2 喜欢 ' 150%' 和 cl.clientid = ' 650450' 解决方案 丑陋的一个: 即使在LINQ中你仍然可以运行SQL查询。示例 IEnumerable< Customer> results = db.ExecuteQuery< Customer> ( @ SELECT c1.custid as CustomerID,c2.custName as ContactName FROM customer1 as c1,customer2为c2 WHERE c1.custid = c2.custid ); 好一个: 在设计师中模拟你的模式,你不应该遇到正确的问题。 代码会像 var query = 来自 cl 客户端 join clad in ClientAddress on cl.id equals clad.clientguid where cl.clientid = ' 650450'&& clad.Address2.StartsWith(' 150') 选择 new {l.clientid,clad.address1,clad.address2} ; select cl.clientid,clad.address1,clad.address2 from Client cljoin ClientAddress clad on cl.id=clad.clientguidwhere clad.Address2 like '150%' and cl.clientid='650450' 解决方案 Ugly one: Even in LINQ you still can run sql queries. ExampleIEnumerable<Customer> results = db.ExecuteQuery<Customer>(@"SELECT c1.custid as CustomerID, c2.custName as ContactName FROM customer1 as c1, customer2 as c2 WHERE c1.custid = c2.custid");Good one: Model your schema in designer, and you should not experience problems with righting.Code will be smth likevar query = from cl in Client join clad in ClientAddress on cl.id equals clad.clientguid where cl.clientid='650450' && clad.Address2.StartsWith('150') select new { l.clientid,clad.address1,clad.address2 }; 这篇关于如何将sql转换为linq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-30 05:24