Linq to EF 和 Linq to SQL 中间Linq 产生的SQL语句

时间:2014-07-22 23:00:53   收藏:0   阅读:553

一,Linq to EF

mamicode.com,码迷
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);
 
            }
             
        }
    }
}
mamicode.com,码迷

 

二,Linq to sql ;

mamicode.com,码迷
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);
            }
        }
    }
}
mamicode.com,码迷

 

最近学习的linq to EF 找到的!

Linq to EF 和 Linq to SQL 中间Linq 产生的SQL语句,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!