tags:

views:

15

answers:

1

How ASP.net webform can be developed by retrieving data from two or more then two tables while using LINQ to SQL. can any body give some code sample for that ----- Thanks!

A: 

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/>");
}
David Hedlund