2012-06-18 52 views
0

我在ASP.NET C#中的应用程序,我使用linq to sql从数据库传递数据。我下面Linq to c#中的sql:如何通过编号获取名称

的Linq代码到SQL:

Figure

我的代码:

public class course_list 
     { 
      //Id of event    
      public int id { get; set; } 
      // Name of event 
      public string name { get; set; } 
      //type of event 
      public string e_type { get; set; } 
      //name of the compay 
      public string compay { get; set; } 
     } 
     // Get data 
     protected void show_event() 
     { 
      for_testDataContext db = new for_testDataContext(); 
      IQueryable<course_list> CourseList = from cl in db.events 
               select new course_list() 
               { 
                id = cl.id, 
                name = cl.name, 
                e_type = cl.e_type_id, // how to get name of e_type 
                compay = cl.company_id //How to get name of company 
               }; 

     } 

如何分配e_type = name of e_type比赛cl.e_type_idcompany = name of compay比赛cl.company_id

回答

4
select new course_list 
{ 
    id = cl.id, 
    name = cl.name, 
    e_type = cl.e_type.name, 
    company = cl.company.name 
}; 
+0

非常感谢。非常容易,但对我来说非常困难:) – Hainlp