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
Abdul Samid
NA
134
519
code first approach oneToMany relation crud operation EF
Jan 12 2020 4:32 AM
I have a school project with asp.net mvc code first approach, in this two model one for student i and one for student enrollment details model name is admission, have one to many relation. at registration time of new student data is saved using admission model by which data is is inserted in both tables, but i want to insert data in only admission table not in student table when new enrollment i.e. enrollment of old student.
Model is As
Student Model
public
int
Id {
get
;
set
; }
[Display(Name =
"SR Number"
)]
[Required(ErrorMessage =
"Can't Left Blank"
)]
public
int
SRNumber {
get
;
set
; }
[Display(Name =
"Name"
)]
[MinLength(3,ErrorMessage =
"Your{0} must be at least {1} characters long"
)]
[MaxLength(40, ErrorMessage =
"Your{0} must be no more than {1} characters"
)]
public
string
Name {
get
;
set
; }
[Display(Name =
"Father"
)]
[MinLength(3, ErrorMessage =
"Your{0} must be at least {1} characters long"
)]
[MaxLength(40, ErrorMessage =
"Your{0} must be no more than {1} characters"
)]
public
string
Father {
get
;
set
; }
[Display(Name =
"Mother"
)]
[MinLength(3, ErrorMessage =
"Your{0} must be at least {1} characters long"
)]
[MaxLength(40, ErrorMessage =
"Your{0} must be no more than {1} characters"
)]
public
string
Mother {
get
;
set
; }
Enrollment Model
public
int
Id {
get
;
set
; }
[DataType(DataType.Date), DisplayFormat(DataFormatString =
"{0:dd/MM/yyyy}"
,
ApplyFormatInEditMode =
true
)]
public
DateTime? AdmissionDate {
get
;
set
; }
public
int
SrNo {
get
;
set
; }
public
AdmissionType AdmissionType {
get
;
set
; }
public
int
ClassMasterId {
get
;
set
; }
public
int
SectionMasterId {
get
;
set
; }
public
ClassMaster ClassMaster {
get
;
set
; }
public
SectionMaster SectionMaster {
get
;
set
; }
public
StudentMaster StudentMaster {
get
;
set
; }
At New Student Registration Data
is
Saved
in
both table
using
(db =
new
SchoolDbContext())
{
db.Admissions.Add(Admission);
db.SaveChanges();
}
But When a old Student is enroll for new class I want To Insert data only in Enrollment.
Please Help Me..
I HAVE Used ASP.NET MVC5 WITH ENTITY FRAMEWORK CODE FIRST APPROACH
Reply
Answers (
1
)
Nhibernet Web App doesn't support multiple users
want to build an image slider