日期:2014-05-20 浏览次数:21107 次
Northwind nw = new Northwind(@"*****");
var select = (from td in nw.T_Dept
where td.DeptId == 1
select new Depart //注意此处
{
DeptId = td.DeptId,
DeptFax = td.DeptFax,
DeptTel = td.DeptTel,
DeptName = td.DeptName,
DeptManId = td.DeptManId
}).FirstOrDefault();
Depart dept = (select ==null? new Depart(): select);
Console.ReadKey();
------解决方案--------------------
http://www.cnblogs.com/JeffreyZhao/archive/2008/02/19/using-translate-method-and-modify-command-text-before-query-in-linq-to-sql.html
Northwind nw = new Northwind(@"*****");
var select = (from td in nw.T_Dept
where td.DeptId == 1
select new
{
DeptId = td.DeptId,
DeptFax = td.DeptFax,
DeptTel = td.DeptTel,
DeptName = td.DeptName,
DeptManId = td.DeptManId
}).FirstOrDefault();
using (dataContext.Connection)
{
Depart dept =nw.ExecuteQuery<Depart>(query, true).FirstOrDefault();
}
------解决方案--------------------