linq to sql 直接使用SQL语句

别样苍茫 2009-08-25 07:39:34
select * from table

如果我想直接作为参数在linq中使用 能行不,是LINQ的哪个方法呢 ?

不想用拉姆达表达式。.
...全文
310 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tomato77 2009-08-31
  • 打赏
  • 举报
回复
ExecuteCommand
yezie 2009-08-28
  • 打赏
  • 举报
回复
3楼正确了,有时需要用到动态表名,只能这样了
xs52121 2009-08-26
  • 打赏
  • 举报
回复
直接写from s in dc.table select s;这样不挺好啊
chen_ya_ping 2009-08-26
  • 打赏
  • 举报
回复
Linq 使用sql没有必要,也不可以这样使用
阿非 2009-08-26
  • 打赏
  • 举报
回复

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvOne" runat="server"></asp:GridView>
<asp:GridView ID="gvTwo" runat="server"></asp:GridView>
</form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Data.Linq;
using System.Data.Linq.SqlClient;

public partial class _Default : System.Web.UI.Page
{


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlConnection con = new SqlConnection("server=.;uid=xxx;pwd=xxx;database=Northwind"))
{
SqlDataAdapter da = new SqlDataAdapter("select top 5 * from Orders ", con);
DataSet ds = new DataSet();
da.Fill(ds, "Orders");
gvOne.DataSource = ds.Tables["Orders"];
gvOne.DataBind();
}//end using block

NorthwindDataClassesDataContext n = new NorthwindDataClassesDataContext("server=.;uid=xxx;pwd=xxx;database=Northwind");


var custQuery = (from cust in n.Orders orderby cust.OrderID select cust).Take(5);
gvTwo.DataSource = custQuery;
gvTwo.DataBind();

}
}
}


NorthwindDataClassesDataContext 是继承自 System.Data.Linq.DataContext 类的
可以通过添加新项 , 选择 LINQ to SQL 类 创建,也可以自定义类继承实现
zhubo_1117 2009-08-26
  • 打赏
  • 举报
回复
ExecuteQuery
wuyq11 2009-08-25
  • 打赏
  • 举报
回复
使用dataContext
NorthwindDataContext _ctx = new NorthwindDataContext();
var query= _ctx.ExecuteQuery<A>(@"select * from a");
_ctx.ExecuteCommand(@"insert into a(name, description) values ({0}, {1})","","");
参考
参考




宝_爸 2009-08-25
  • 打赏
  • 举报
回复
看看这个能不能帮你:
http://www.codeproject.com/KB/linq/sqlfromlinq.aspx
宝_爸 2009-08-25
  • 打赏
  • 举报
回复
不了解LINQ, 顶一下吧。

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧