Coding Fun Html Part 10 Working with multiple tables in mvc

Part 10 Working with multiple tables in mvc

Text version of the video


All ASP .NET MVC Text Articles

All ASP .NET MVC Slides

All Dot Net and SQL Server Tutorials in…

Tags: , , , , , , , , , , , , , ,

27 thoughts on “Part 10 Working with multiple tables in mvc”

  1. Do you talk anywhere in one of the other tutorials about why one method sends a List<Employee> and the other recieves an IEnumerable<Employee>. I hope so because it is a good – and very deliberate – construct.

  2. Please anyone Help :
    For me error occurred while running: VStudio — An error occurred while executing the command definition. See the inner exception for details. browser — Invalid column name 'DepartmentId'.

    Invalid column name 'DepartmentId'.
    3.In Browser — Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'DepartmentId'.

    Invalid column name 'DepartmentId'.
    I'm fully confused and took lot of time to solve but I can't…!

  3. niyazi tok says:

    What is the last parameter you passed as "null" ? What is it for? Thx.

  4. Hu Wei Ng says:

    Hi. Can I do this tutorial on .net core? There is not much tutorials from kudvenkat on core mvc so I will use this as reference.Please advise

  5. Neeraj Yadav says:

    So what's the use of forenkey in between this two table

  6. Hi, can you help me? i am having an "Invalid column name 'Department_ID' error when running the project.

  7. nice , but what is the use of = public List[Employee] Employees { get; set; } ? without this also i can run the same output

  8. EntityType 'Department' has no key defined. Define the key for this EntityType.
    Departments: EntityType: EntitySet 'Departments' is based on type 'Department' that has no keys defined.

    Source Error:

    Line 16: {
    Line 17: EmployeeContext employeeContext = new EmployeeContext();
    Line 18: List<Department> departmentlst =employeeContext.Departments.ToList();
    Line 19: return View(departmentlst);
    Line 20: }

    Source File: D:MVCWORKMVCLinkMVCLinkControllersDepartmentController.cs Line: 18

  9. "MVCDemo.Models.Department: : EntityType 'Department' has no key defined. Define the key for this EntityType.
    Departments: EntityType: EntitySet 'Departments' is based on type" Can Anybody help me on this issue !!!!!!!!!

  10. If you get the errors below while fetching Data:

    An exception of type 'System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code
    One or more validation errors were detected during model generation:
    FirstMVCProj.Models.Department: : EntityType 'Department' has no key defined. Define the key for this EntityType.
    Departments: EntityType: EntitySet 'Departments' is based on type 'Department' that has no keys defined.

    Solution: Please Add [Key] which presents under System.ComponentModel.DataAnnotations; on both of your tables.
    The Table will look like This:
    Add this: using System.ComponentModel.DataAnnotations;

    public class Department
    public int DeptId { get; set; }
    public string DeptName { get; set; }
    public List<Employee> Employees { get; set; }
    public class Employee
    public int EmployeeID { get; set; }
    public string Name { get; set; }
    public string Gender { get; set; }
    public string City { get; set; }
    public int DeptID { get; set; }

  11. Zohaib Rao says:

    The model item passed into the dictionary is of type 'System.Data.Entity.ModelConfiguration.ModelValidationException', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MVC45Practice.Models.Employee]'.

    when i add Department controller it throws an Exception
    and previously working Employee Controller also start throwing above mentioned error.

  12. Any one has a working code? can you share a link?

  13. Code Rag says:

    get is accessor and set is mutator. get;set; are not 'accesors'. sorry to interrupt; just reminding.

  14. Nikita gupta says:

    Why i am getting Invalid column name 'DepartmentId'. in EmployeeContent employeeContent = new EmployeeContent();
    Line 15: List<Employee> employees = employeeContent.Employees.Where(emp => emp.DepartmentId == departmentId).ToList();

  15. Reza Taba says:

    Solution for these issues:
    1- Invalid column name Department_DeptId
    2- Invalid Key
    3- Entity issues

    Using [Key] or Foreign Key didn't work.

    1- Change your EmployeeContext file to something more general.
    For example: ProjectContext

    2- Now In ProjectContext file create two classes which contain your EmployeeContext and DepartmentContext as below:

    using System.Data.Entity;

    namespace MVCDemo.Models
    public class EmployeeContext : DbContext
    public DbSet<Employee> EmployeesContextTbl { get; set; }

    public class DepartmentContext : DbContext
    public DbSet<Department> DepartmentContextTbl { get; set; }

    3- Modify your Web.config file.
    <add name="EmployeeContext"
    connectionString="server=.; database=Sample; integrated security=SSPI"

    <add name="DepartmentContext"
    connectionString="server=.; database=Sample; integrated security=SSPI"

    4- Modify Global.asax file:

    5- Now you can use your connections for EmployeeContext and DepartmentContext separately.

    I read somewhere since Vinket was using Visual Studio 2010 there was no issue. However, it seems this issue started with the newer versions.

    Good luck.

  16. qiming cheng says:

    What is the use of List<Employee> Employees property in Department Model Class?

  17. Be Learnt says:

    is this using entity framework? or simple mvc ?

  18. Jay Patel says:

    Hi Venkt, Question: Do you have a similar video where backend is simply an XML file but not a SQL server database? I will be working on a UI where there is no database involved. the Data will be pulled from an XML file. Or Do you have any other suggestions? Thank you

  19. Ramesh Kumar says:

    Thank You so much good Tutorial

  20. Buskila Maor says:

    It works fine on the local machine but how do i make it work after publishing to IIS? there has to be a change in the connectionString…..any help?

  21. Please help me with this error : " The underlying provider failed on Open"

  22. Amol Kendre says:

    It was realy nice, Thank you
    But I have one doubt
    If you see the url of Employee details page so url is
    Here Employee is controller class name and Details is action name and 2 is employe id which is parameter to Details action method
    And if you see URL of Employee Index page is
    Here Employee is controller class but how I can identify which action method get invoked ?
    Sorry My English is poor.
    Any one have idea about it

  23. hello bro .if u getting error checking your table data , u must have 4 field in tblEmployee(EmployeeId,Name,Gender,City,DepartmentId).

  24. hello my friend ( lovers) ! if you getting some error in this video . here i will help you ! if you intresting chat me = . i am only stupid people

Leave a Reply

Your email address will not be published. Required fields are marked *