TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tangara G
NA
298
93.6k
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
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
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<FlightSchedule> FlightSchedules { get; set; }
}
}
And here's the page that is giving me problem.
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; }
}
}
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 ?
Reply
Answers (
1
)
ITextSharp PDF in MVC
How to save selected tree view node id in action link