开发者

LINQ to SQL ASP.net

How ASP.net webform can be developed by retr开发者_JAVA百科ieving data from two or more then two tables while using LINQ to SQL. can any body give some code sample for that ----- Thanks!


This is a simple snippet of an application that retrieves data from two tables in LINQ to SQL. If you want something more specific, please ask a more specific question.

DataContext db = new DataContext();

var users = db.Users.OrderByDescending(u => u.LastLogin).Take(5);
var messages = db.Messags.OrderByDescending(m => m.PublishDate).Take(5);

Response.Write("<b>Last 5 users logged in:</b><br/>");
foreach(User u in users) {
   Response.Write(u.Username + "<br/>");
}

Response.Write("<b>Last 5 messages:</b><br/>");
foreac(Message m in messages) {
   Response.Write(m.Title + "<br/>");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜