Hi,
I am getting the following error :
Error 4 'PresentationLayer.AeroLionEntities1' does not contain a definition for 'FlightSchedule' and no extension method 'FlightSchedule' accepting a first argument of type 'PresentationLayer.AeroLionEntities1' could be found (are you missing a using directive or an assembly reference?) C:\Users\kgshi\documents\visual studio 2013\Projects\AeroLion\PresentationLayer\FlightScheduleEF.aspx.cs 22 35 PresentationLayer
Here's the context page ? EFAeroLion.Context.cs
Here's the context page ? EFAeroLion.Context.cs
- //------------------------------------------------------------------------------
- //
- // This code was generated from a template.
- //
- // Manual changes to this file may cause unexpected behavior in your application.
- // Manual changes to this file will be overwritten if the code is regenerated.
- //
- //------------------------------------------------------------------------------
- namespace PresentationLayer
- {
- using System;
- using System.Data.Entity;
- using System.Data.Entity.Infrastructure;
- public partial class AeroLionEntities1 : DbContext
- {
- public AeroLionEntities1()
- : base("name=AeroLionEntities1")
- {
- }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- throw new UnintentionalCodeFirstException();
- }
- public virtual DbSet
FlightSchedules { get; set; } - }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace PresentationLayer
- {
- public partial class FlightScheduleEF : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void Retrieve_button_click(object sender, EventArgs e)
- {
- using(AeroLionEntities1 cntx = new AeroLionEntities1())
- {
- var flight = cntx.FlightSchedule.FirstOrDefault(maxSeatsTextBox => m.flightId == flightIDTextBox.Text);
- if(flight != null)
- {
- flightIDTextBox.Text = flight.flightId;
- fromCityTextBox.Text = flight.fromCity;
- toCityTextBox.Text = flight.toCity;
- departTimeTextBox.Text = flight.departTime;
- arrivalTimeTextBox.Text = flight.arrivalTime;
- fareTextBox.Text = flight.fare.ToString();
- maxSeatsTextBox.Text = flight.maxSeats.ToString();
- }
- }
- }
- protected void Create_click_button(object sender, EventArgs e)
- {
- using(AeroLionEntities1 cntx = new AeroLionEntities1())
- {
- FlightSchedule addFlight = new FlightSchedule();
- addFlight.flightId = flightIDTextBox.Text;
- addFlight.fromCity = fromCityTextBox.Text;
- addFlight.toCity = toCityTextBox.Text;
- addFlight.departTime = departTimeTextBox.Text;
- addFlight.arrivalTime = arrivalTimeTextBox.Text;
- if (fareTextBox.Text != string.Empty)
- {
- addFlight.fare = Convert.ToDecimal(fareTextBox.Text);
- }
- if (maxSeatsTextBox.Text != string.Empty)
- {
- addFlight.maxSeats = Convert.ToInt32(maxSeatsTextBox.Text);
- }
- cntx.FlightSchedules.Add();
- cntx.SaveChanges();
- messageLabel.Text = "New Flight Schedule added Successfully";
- }
- }
- protected void Upate_button_click(object sender, EventArgs e)
- {
- using(AeroLionEntities1 cntx = new AeroLionEntities1())
- {
- var flight = cntx.FlightSchedule.FirstOrDefault(m => m.flight == flightIDTextBox.Text);
- if(flight != null)
- {
- flight.flightId = flightTextBox.Text;
- flight.fromCity = fromCityTextBox.Text;
- flight.toCity = toCityTextBox.Text;
- if (!string.IsNullOrEmpty(maxSeatsTextBox.Text))
- {
- flight.maxSeats = Convert.ToInt32(maxSeatsTextBox.Text);
- }
- if (!string.IsNullOrEmpty(fareTextBox.Text))
- {
- flight.fare = Convert.ToDecimal(fareTextBox;)
- }
- flight.arrivalTime = arrivalTimeTextBox.Text;
- flight.departTime = departTimeTextBox.Text;
- cntx.SaveChanges();
- messageLabel.Text = "Update Successful";
- }
- }
- }
- protected void Delete_button_Click(object sender, EventArgs e)
- {
- using (AeroLionEntities1 cntx = new AeroLionEntities1())
- {
- var flight = cntx.FlightSchedule.FirstOrDefault(m => m.flightId == flightIdTextBox.Text);
- if (flight != null)
- {
- cntx.DeleteObject(data);
- cntx.SaveChanges();
- ClearFields();
- messageLabel.Text = "Record deleted Successfully";
- }
- }
- }
- private void ClearFields()
- {
- flightIDTextBox.Text = string.Empty;
- fromCityTextBox.Text = string.Empty;
- toCityTextBox.Text = string.Empty;
- arrivalTimeTextBox.Text = string.Empty;
- departTimeTextBox.Text = string.Empty;
- fareTextBox.Text = string.Empty;
- maxSeatsTextBox.Text = string.Empty;
- }
- public object data { get; set; }
- }
- }
Furthermore, the AddToFlightSchedule(addFlight) doesn't exist when I generated the entity framework edmx based on FlightSchedule.dbo....
cntx.AddToFlightSchedule(addFlight);
Can I know am I supposed to write my own method or it is supposed to be generated by the VS 2013 ?
Nilesh SawardekarPosted Jul 26, 2016, 12:31 AM