Linq to EF 和 Linq to SQL 中间Linq 产生的SQL语句
时间:2014-07-22 23:00:53
收藏:0
阅读:553
一,Linq to EF
using System; using System.Runtime.CompilerServices; using System.Linq; using System.Data; namespace EntityframeworkSQL { class Program { static void Main(string[] args) { using (CustomerEntities customerEntities = new CustomerEntities()) { var customerNames = from c in customerEntities.Customers select c.CustomerName; string sql = ((System.Data.Objects.ObjectQuery)customerNames).ToTraceString(); Console.WriteLine(sql); } } } }
二,Linq to sql ;
using System; using System.Linq; using System.Data; namespace LinqToSQL { class Program { static void Main(string[] args) { using (CustomerDataContext customerContext = new CustomerDataContext()) { var customerNames = from c in customerContext.Customers select c.CustomerName; string sql = customerContext.GetCommand(customerNames).CommandText; Console.WriteLine(sql); } } } }
最近学习的linq to EF 找到的!
评论(0)