Ошибка создания экземпляра DataContext

-2

Поэтому я пытаюсь изучить ASP.net, AJAX, Json и JQuery с помощью этого руководства: http://www.search-this.com/2010/04/26/asp-net-linq-jquery-json-ajax-oh -my/#

Однако я даже не могу получить первый бит кода.

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
    Подождите, у меня нет ничего, кроме этого кода ... Я совершенно новичок в базах данных и все. Что я должен делать?
Теги:

1 ответ

0

Попробуйте этот учебник. Тот, который вы используете, выглядит как датированный.

https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net- MVC-приложения

Ещё вопросы

Сообщество Overcoder
Наверх
Меню