Tangara G

Tangara G

  • NA
  • 298
  • 90.1k

I am not getting the CRUD method from my generated entities

Jul 21 2016 11:17 PM
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
 
  1. //------------------------------------------------------------------------------  
  2. // <auto-generated>  
  3. //     This code was generated from a template.  
  4. //  
  5. //     Manual changes to this file may cause unexpected behavior in your application.  
  6. //     Manual changes to this file will be overwritten if the code is regenerated.  
  7. // </auto-generated>  
  8. //------------------------------------------------------------------------------  
  9.   
  10. namespace PresentationLayer  
  11. {  
  12.     using System;  
  13.     using System.Data.Entity;  
  14.     using System.Data.Entity.Infrastructure;  
  15.       
  16.     public partial class AeroLionEntities1 : DbContext  
  17.     {  
  18.         public AeroLionEntities1()  
  19.             : base("name=AeroLionEntities1")  
  20.         {  
  21.         }  
  22.       
  23.         protected override void OnModelCreating(DbModelBuilder modelBuilder)  
  24.         {  
  25.             throw new UnintentionalCodeFirstException();  
  26.         }  
  27.       
  28.   
  29.   
  30.         public virtual DbSet<FlightSchedule> FlightSchedules { get; set; }  
  31.     }  

 And here's the page that is giving me problem.
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7.   
  8.   
  9. namespace PresentationLayer  
  10. {  
  11.     public partial class FlightScheduleEF : System.Web.UI.Page  
  12.     {  
  13.         protected void Page_Load(object sender, EventArgs e)  
  14.         {  
  15.   
  16.         }  
  17.   
  18.         protected void Retrieve_button_click(object sender, EventArgs e)  
  19.         {  
  20.             using(AeroLionEntities1 cntx = new AeroLionEntities1())  
  21.             {  
  22.                 var flight = cntx.FlightSchedule.FirstOrDefault(maxSeatsTextBox => m.flightId == flightIDTextBox.Text);  
  23.                 if(flight != null)  
  24.                 {  
  25.                     flightIDTextBox.Text = flight.flightId;  
  26.                     fromCityTextBox.Text = flight.fromCity;  
  27.                     toCityTextBox.Text = flight.toCity;  
  28.                     departTimeTextBox.Text = flight.departTime;  
  29.                     arrivalTimeTextBox.Text = flight.arrivalTime;  
  30.                     fareTextBox.Text = flight.fare.ToString();  
  31.                     maxSeatsTextBox.Text = flight.maxSeats.ToString();  
  32.                 }  
  33.             }  
  34.         }  
  35.   
  36.         protected void Create_click_button(object sender, EventArgs e)  
  37.         {  
  38.   
  39.             using(AeroLionEntities1 cntx = new AeroLionEntities1())  
  40.             {  
  41.   
  42.                 FlightSchedule addFlight = new FlightSchedule();  
  43.                 addFlight.flightId = flightIDTextBox.Text;  
  44.                 addFlight.fromCity = fromCityTextBox.Text;  
  45.                 addFlight.toCity = toCityTextBox.Text;  
  46.                 addFlight.departTime = departTimeTextBox.Text;  
  47.                 addFlight.arrivalTime = arrivalTimeTextBox.Text;  
  48.   
  49.                 if (fareTextBox.Text != string.Empty)  
  50.                 {  
  51.                     addFlight.fare = Convert.ToDecimal(fareTextBox.Text);  
  52.                 }  
  53.   
  54.                 if (maxSeatsTextBox.Text != string.Empty)  
  55.                 {  
  56.                     addFlight.maxSeats = Convert.ToInt32(maxSeatsTextBox.Text);  
  57.   
  58.                 }  
  59.   
  60.                 cntx.FlightSchedules.Add();  
  61.                     cntx.SaveChanges();  
  62.                 messageLabel.Text = "New Flight Schedule added Successfully";  
  63.   
  64.   
  65.             }  
  66.   
  67.   
  68.         }  
  69.   
  70.         protected void Upate_button_click(object sender, EventArgs e)  
  71.         {  
  72.   
  73.             using(AeroLionEntities1 cntx = new AeroLionEntities1())  
  74.             {  
  75.                 var flight = cntx.FlightSchedule.FirstOrDefault(m => m.flight == flightIDTextBox.Text);  
  76.   
  77.                 if(flight != null)  
  78.                 {  
  79.   
  80.                     flight.flightId = flightTextBox.Text;  
  81.                     flight.fromCity = fromCityTextBox.Text;  
  82.                     flight.toCity = toCityTextBox.Text;  
  83.   
  84.                     if (!string.IsNullOrEmpty(maxSeatsTextBox.Text))  
  85.                     {  
  86.                         flight.maxSeats = Convert.ToInt32(maxSeatsTextBox.Text);  
  87.   
  88.                     }  
  89.   
  90.                     if (!string.IsNullOrEmpty(fareTextBox.Text))  
  91.                     {  
  92.                         flight.fare = Convert.ToDecimal(fareTextBox;)  
  93.                     }  
  94.                     flight.arrivalTime = arrivalTimeTextBox.Text;  
  95.                     flight.departTime = departTimeTextBox.Text;  
  96.   
  97.                     cntx.SaveChanges();  
  98.                     messageLabel.Text = "Update Successful";  
  99.   
  100.   
  101.                     }  
  102.             }  
  103.         }  
  104.   
  105.         protected void Delete_button_Click(object sender, EventArgs e)  
  106.         {  
  107.   
  108.             using (AeroLionEntities1 cntx = new AeroLionEntities1())  
  109.             {  
  110.                 var flight = cntx.FlightSchedule.FirstOrDefault(m => m.flightId == flightIdTextBox.Text);  
  111.                 if (flight != null)  
  112.                 {  
  113.                     cntx.DeleteObject(data);  
  114.                     cntx.SaveChanges();  
  115.                     ClearFields();  
  116.                     messageLabel.Text = "Record deleted Successfully";  
  117.                 }  
  118.             }  
  119.         }  
  120.   
  121.         private void ClearFields()  
  122.         {  
  123.             flightIDTextBox.Text = string.Empty;  
  124.             fromCityTextBox.Text = string.Empty;  
  125.             toCityTextBox.Text = string.Empty;  
  126.             arrivalTimeTextBox.Text = string.Empty;  
  127.             departTimeTextBox.Text = string.Empty;  
  128.             fareTextBox.Text = string.Empty;  
  129.             maxSeatsTextBox.Text = string.Empty;  
  130.         }  
  131.   
  132.         public object data { get; set; }  
  133.     }  

My problem is that after the cntx. FlightSchedule doesn't show up but FlightSchedules show up.
 
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 ?
 
 
 
 
 

Answers (1)