ahmedsa ahmedsa - 2 months ago 114x 0x

my diagram and interface found in this link


I need to make multiple insert to multiple table have relation with each other

all id in all tables identity increment

what i need actually when user click submit

Save the following data

Name,Email,Salary,DistrictId in table Employee

EmployeeId,CourseId in table EmployeeCourse

EmployeeId,LanaguageId,LevelId in table EmployeeLangage

when do insert to multiple table it give me error
i face problem in this line


how to assign list to object

it give me this error

cannot implicity convert convert System.collection.Generic.list to System.collection.Generic.Icollection


insert data to multiple table relation in same time

public class Customemployee
        public string Name { get; set; }
        public string Salary { get; set; }

        public string Email { get; set; }
        public int DistrictId { get; set; }

        public List<Empcourse> Courses { get; set; }
        public List<Emplangauge> Langs { get; set; }
    public class Empcourse
        public int Id { get; set; }
        public int EmployeeId { get; set; }
        public int CourseId { get; set; }
    public class Emplangauge
        public int Id { get; set; }

        public int LevelId { get; set; }
        public int LanguageId { get; set; }



public class empcourseController : Controller
        mycourseEntities db = new mycourseEntities();
        // GET: empcourse
        public ActionResult Index()
            return View();
        public ActionResult Create()
            ViewBag.CountryId = new SelectList(db.Countries, "Id", "CountryName");
            ViewBag.LanaguageId = new SelectList(db.Languages.ToList(), "Id", "LnaguageName");
            ViewBag.LevelId = new SelectList(db.Levels.ToList(), "Id", "LevelName");
            ViewBag.CourseId = new SelectList(db.Courses.ToList(), "Id", "CourseName");
            return View();
        public ActionResult Create(FormCollection form)
            Customemployee cemp = new Customemployee();
            Employee emp = new Employee();
            emp.Name = form["Name"].ToString();
            emp.Salary =Convert.ToInt32(form["Salary"]);
            emp.Email = form["Email"].ToString();
            emp.DistrictId = Convert.ToInt32(form["DistrictId"]);

            var coursesId = form["Courses"];

            string[] coursesIds = null;

            if (coursesId != null)
                coursesIds = coursesId.Split(',');

            List<Empcourse> courses = new List<Empcourse>();

            foreach (var item in coursesIds)
                Empcourse ecour = new Empcourse();
                ecour.EmployeeId = emp.Id;
                ecour.CourseId = Convert.ToInt32(item);
            emp.EmployeeCourses = courses
return view