none
How to get team entities details in other main entities in MVC 5? RRS feed

  • Question

  • Hi,

    I have two entities[Team],[MainEntry]. Now i want to get all team details in dropdown while entring in MainEntry view

    in MVC.

    In other word in the MainEntry views i want get all team details in the dropdown.

    Im using VS-2015, MVC5, EF6 with Code first migration.

    public class Team { public int TeamId { get; set; } public string TeamName { get; set; } public string TeamAge { get; set; } public string TeamLocation { get; set; } } public class MainEntry { public int MainEntryId { get; set; } public string TeamAssignment { get; set; } public string Role { get; set; } public string Series { get; set; } public string Stock { get; set; } public string Points { get; set; } public sting Teamname {get; set;} //(dropdown fill) public string Teamage {get;set;} //(dropwon fill) public string TeamLocation {get;set;} //(dropwon fill) }

    Thanks in advance..
    Thursday, November 24, 2016 5:41 AM

All replies

  • Hi,

      I have 2 entities and <g class="gr_ gr_12 gr-alert gr_tiny gr_spell gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="12" id="12">i</g>  want to fetch details at the time of MainEntry in  mvc5 using EF6 code first migration. How to map the relation between them?

    Note: The team details <g class="gr_ gr_9 gr-alert gr_tiny gr_spell gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="9" id="9">i</g> want in dropdown control in the MainEntry view. 

    public class Team { public int TeamId { get; set; } public string TeamName { get; set; } public string TeamAge { get; set; } public string TeamLocation { get; set; } } public class MainEntry { public int MainEntryId { get; set; } public string TeamAssignment { get; set; } public string Role { get; set; } public string Series { get; set; } public string Stock { get; set; } public string Points { get; set; }

    public sting Teamname {get; set;}

    public string Teamage {get;set;}

    public string TeamLocation {get;set;}

     

    }

    Thanks in advance,

     



    Thursday, November 24, 2016 3:23 AM
  • Hi KHAN.S,

    According to your description, it seems that you want to a one-to-many relationship. one MainEntry has many Team. Please define your entity class like below. you could fill you dropdown control via Teams collection.

    public class Team
        {     
       public int TeamId { get; set; }
           
            public string TeamName { get; set; }
    
            public string TeamAge { get; set; }
            public string TeamLocation { get; set; }  
    
           public virtual MainEntry MainEntry { get; set; }   
      
    }
    
    
    public class MainEntry
     {     
            public int MainEntryId { get; set; }
           
            public string TeamAssignment { get; set; }
    
            public string Role { get; set; }
            public string Series { get; set; }  
            public string Stock { get; set; } 
            public string Points { get; set; }
            public virtual ICollection<Team> Teams{ get; set; }   
    }
    

    For more information, please refer to:

    https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-a-more-complex-data-model-for-an-asp-net-mvc-application

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 24, 2016 8:57 AM
    Moderator
  • No its not working as i want. I think there should be some foreign key required. To get [team] entities details in [mainentry] view. !!!

    Thursday, November 24, 2016 10:00 AM
  • Ok,

    I got my answer as given link by Cole Wu.

    Thursday, November 24, 2016 11:45 AM
  • Hi KHAN.S,

    I am glad to know you solved this problem. If the reply is helpful to you, please mark it as answer.

    It will be very beneficial for other community members who have the similar questions. 


    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 25, 2016 12:49 AM
    Moderator