Delete row ASP.NET MVC ADO.NET entity Model

ado.net asp.net asp.net-mvc c# entity-framework

Question

I just started using the asp.net MVC environment.

I'm using the ado.net entity data model to automatically create the database, thus I'm attempting to delete ROW from three tables/entities. However, when my delete function is used, just ROW from one table gets destroyed.

PS: I've already established a connection between three tables.

My controller is here:

    [HttpPost, ActionName("Delete")]
    [ValidateAntiForgeryToken]
    public ActionResult DeleteConfirmed(int id)
    {
        // i've edited this code, i think the problem lies in this code bellow
        // start edited code
        ms_student ms_student = db.ms_student
             .Include(i => i.ms_person) 
             .Include(i => i.ms_person.ms_user)
             .Where(i => i.user_id_student == id)
             .Single(); 
        // end edited code

        db.ms_student.Remove(ms_student);
        db.SaveChanges();
        return RedirectToAction("Index");
    }

My ms user model is as follows:

namespace test.Models
{
    using System;
    using System.Collections.Generic;

    public partial class ms_user
    {
        public int ID { get; set; }
        public string password { get; set; }
        public string salt { get; set; }
        public Nullable<int> administrative_type_id { get; set; }
        public string email_login { get; set; }

        public virtual ms_person ms_person { get; set; }
    }
}

Ms Person model is this

namespace test.Models
{
    using System;
    using System.Collections.Generic;

    public partial class ms_person
    {  
        public int ID { get; set; }
        public Nullable<int> family_id { get; set; }
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string email { get; set; }
        public string address { get; set; }
        public string phone_address { get; set; }
        public string mobile_phone_number { get; set; }
        public string gender { get; set; }
        public Nullable<System.DateTime> date_of_bith { get; set; }
        public Nullable<System.DateTime> date_start { get; set; }
        public Nullable<System.DateTime> date_end { get; set; }
        public string status { get; set; }
        public string identification_ID { get; set; }
        public string passport { get; set; }
        public Nullable<int> user_type_id { get; set; }
        public string file_image { get; set; }

        public virtual ms_student ms_student { get; set; }
        public virtual ms_user ms_user { get; set; }

    }
}

And finally, my ms person model

namespace test.Models
{
    using System;
    using System.Collections.Generic;

    public partial class ms_student
    {
        public int user_id_student { get; set; }
        public int student_code { get; set; }
        public int course_id { get; set; }
        public string degree { get; set; }
        public Nullable<int> current_semester { get; set; }
        public string cuti_session { get; set; }

        public virtual ms_person ms_person { get; set; }
    }
}

Just so you know, the model code is automatically produced. I'm using an ado.net entity model, and the only table or entity that was deleted was the ms student table (sorry, i'm not sure if that should be called a model, entity, or table).

the user id student actually is the FK also the PK of ms person and (foolishly of mine for the different naming) the ID on ms person are auto increment PK the ID on ms user actually is the FK also the PK of ms person

I appreciate you,

1
1
7/17/2014 10:00:34 AM

Accepted Answer

ZZZ_tmp
5
7/18/2014 7:10:09 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow