locked
proper way to save list of items List<tags> tags, proper way to display suggested text RRS feed

  • Question

  • User-1227792608 posted

    Hello,

    I have an object (lets call it post) which the user will have the option to add hashtags (comma separated). So from my research I should not use List<tags> on my model because it will not persist through entity framework. so with that said I was told to create a viewModel with list of <tags> and have my model just save List<int> tagId's 

    if this is the case I would still like to save the objects <tags> in the database so that way tags are not repeated i can do a many to many relationship with posts to tags can anyone help clear up this information?     

    furthermore I will eventually run into the issue with user with many posts .... if i cannot save a List<posts>  how can i persist the one to many relationship? 

    thank you for your patience and your help.


    ----------------------------------

    two part question.   
    if i have multiple saved tags in the database I do not want to duplicate and i would like to help the user autocomplete. can someone also help with the ajax or jquery to help the user with this? I'm assuming they go hand in hand with the save.

    Wednesday, December 12, 2018 1:18 AM

All replies

  • User475983607 posted
    If you wish to save data in a database then do so. If you want unique values in a column then write code that meets the requirement.

    If you want auto complete then do a quick Google to find an API that suites your needs.

    If you need help with your code then post your code along with your expected results and actual results.
    Wednesday, December 12, 2018 1:53 AM
  • User1724605321 posted

    Hi moihawk ,

    if this is the case I would still like to save the objects <tags> in the database so that way tags are not repeated i can do a many to many relationship with posts to tags can anyone help clear up this information?     

    Please refer to tutorial:  Configure Many-to-Many Relationships in Code-First

    if this is the case I would still like to save the objects <tags> in the database so that way tags are not repeated i can do a many to many relationship with posts to tags can anyone help clear up this information?   

    Your posts and tags are many to many relationship , users and posts are one to many relationship .

    if i have multiple saved tags in the database I do not want to duplicate and i would like to help the user autocomplete

    You can find a lot of plugins could meet your requirement , for example Jquery ui autocomplete plugin :

    https://jqueryui.com/autocomplete/ 

    https://www.aspsnippets.com/Articles/jQuery-AutoComplete-from-Database-in-ASPNet-MVC.aspx 

    Best Regards,

    Nan Yu

    Thursday, December 13, 2018 3:21 AM
  • User-1227792608 posted

    Nan Yu 

    Thank you I will try to implement this before I ask anymore questions and if I have any i will be sure to add code and exact questions or errors. thank you again for pointing me in the right direction 

    Monday, December 24, 2018 7:38 PM