码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2014-07-22 23:00:53      阅读:553      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   os   

一,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

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

标签:style   blog   http   java   color   os   

原文地址:http://www.cnblogs.com/echo-pang/p/3702955.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!