2016-07-10 73 views
-2

所以我想学ASP.net,AJAX,JSON和JQuery本指南: http://www.search-this.com/2010/04/26/asp-net-linq-jquery-json-ajax-oh-my/#错误创建一个DataContext实例

但是我甚至不能获得代码的第一位工作。

public class CourseReservations 
{ 
    public long CourseId { get; set; } 
    public string Course { get; set; } 
    public string Time { get; set; } 
    public int Holes { get; set; } 
    public int Golfers { get; set; } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
} 

[WebMethod] 
public List<CourseReservations> GetGolfCourseReservations() 
{ 
    using (DataContext dc = new DataContext()) // Creating the Error, it says that I can't have a DataContext constructor that takes 0 arguments... I am just questioning how this code can work for him then?? 
    { 
     var query = from res in dc.GolfReservations // I get an Error here too, saying there is no definition for GolfReservations 
        where res.CourseId == 1 
        select new CourseReservations 
        { 
         CourseId = res.CourseId, 
         Course = res.GolfCourse.CourseName, 
         Time = res.DataAndTime.ToShortTimeString(), 
         Holes = res.Holes, 
         Golfers = res.Golfers, 
         FirstName = res.Aspnet_User.GolfUser.FirstName, 
         LastName = res.Aspnet_User.GolfUser.LastName, 
        }; 

     return query.ToList(); 
    } 
} 

希望有人能帮助!

+0

你的DataContext是什么样的? –

+0

等一下,我没有别的东西比这个代码...我完全是数据库和所有新手。我该怎么办? – coding4life

回答