locked
Populating Collection property in a Class RRS feed

  • Question

  • User-305496339 posted

    I was wondering what is best practice for populating a collection property of a Class using liq to sql. Thanks !

    Tuesday, February 13, 2018 6:50 PM

Answers

  • User475983607 posted

    rkrex

    I was wondering what is best practice for populating a collection property of a Class using liq to sql. Thanks !

    There is really no answer to this question as it depends on the situation.   For example, lazy loading a property when needed.  

    Are you having a problem or error?  Is there anyway you can provide example code?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 13, 2018 7:04 PM
  • User475983607 posted

    Thanks for your reply. I dont have any code I was just wondering how is this normally done. Or is there a sample tutorial that might show me how this is done. But obviously this is dealing with the conceptual model of a one to many relationship in my domain model. So I have two classes and one or the parent model is using the (Many) child class as a list or collection property. I just wanted to know the scenarios regarding how this is normally implemented for display in a View. Thanks !

    Generally an entity model is NOT passed to the View but rather a ViewModel is passed to the View.   This is not a rule.  It's more a natural progression due to nature of building a UI (Views).  Models are based on database tables and have fields like IDs and timestamps that are meaningless to humans or the UI design.  

    It is common to have a mapping layer between a model (the db tables) and what the View needs to build a proper UI.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 13, 2018 7:29 PM
  • User475983607 posted

    What I am saying is that we spent a lot of time on my previous question regarding partial views. I understand how everything works in that scenario. But I was wondering would it have been more efficient to have just passed a view model with Parent and child data and traversed the child records in the view model and shown the Parent Records and Child records all in one view. As opposed to how i did it by having a parent view with the master record and using a partial view to show its child records. I hope I am making sense. Thanks !

    If I recall the previous post had to do with AJAX, updating the DOM, and fundamental HTTP.  In that regard, it is easier to pass everything the view needs rather than making an AJAX request when the page loads in the browser and fetching related records.  But it depends on your UI design.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 14, 2018 11:22 AM

All replies

  • User475983607 posted

    rkrex

    I was wondering what is best practice for populating a collection property of a Class using liq to sql. Thanks !

    There is really no answer to this question as it depends on the situation.   For example, lazy loading a property when needed.  

    Are you having a problem or error?  Is there anyway you can provide example code?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 13, 2018 7:04 PM
  • User-305496339 posted

    Thanks for your reply. I dont have any code I was just wondering how is this normally done. Or is there a sample tutorial that might show me how this is done. But obviously this is dealing with the conceptual model of a one to many relationship in my domain model. So I have two classes and one or the parent model is using the (Many) child class as a list or collection property. I just wanted to know the scenarios regarding how this is normally implemented for display in a View. Thanks !

    Tuesday, February 13, 2018 7:14 PM
  • User475983607 posted

    Thanks for your reply. I dont have any code I was just wondering how is this normally done. Or is there a sample tutorial that might show me how this is done. But obviously this is dealing with the conceptual model of a one to many relationship in my domain model. So I have two classes and one or the parent model is using the (Many) child class as a list or collection property. I just wanted to know the scenarios regarding how this is normally implemented for display in a View. Thanks !

    Generally an entity model is NOT passed to the View but rather a ViewModel is passed to the View.   This is not a rule.  It's more a natural progression due to nature of building a UI (Views).  Models are based on database tables and have fields like IDs and timestamps that are meaningless to humans or the UI design.  

    It is common to have a mapping layer between a model (the db tables) and what the View needs to build a proper UI.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 13, 2018 7:29 PM
  • User-305496339 posted

    Can you give me an example of this mapping layer please. Thanks! If i can learn this better then I can contribute more in the forum.

    Tuesday, February 13, 2018 7:39 PM
  • User-305496339 posted

    What I am saying is that we spent a lot of time on my previous question regarding partial views. I understand how everything works in that scenario. But I was wondering would it have been more efficient to have just passed a view model with Parent and child data and traversed the child records in the view model and shown the Parent Records and Child records all in one view. As opposed to how i did it by having a parent view with the master record and using a partial view to show its child records. I hope I am making sense. Thanks !

    Tuesday, February 13, 2018 8:13 PM
  • User475983607 posted

    What I am saying is that we spent a lot of time on my previous question regarding partial views. I understand how everything works in that scenario. But I was wondering would it have been more efficient to have just passed a view model with Parent and child data and traversed the child records in the view model and shown the Parent Records and Child records all in one view. As opposed to how i did it by having a parent view with the master record and using a partial view to show its child records. I hope I am making sense. Thanks !

    If I recall the previous post had to do with AJAX, updating the DOM, and fundamental HTTP.  In that regard, it is easier to pass everything the view needs rather than making an AJAX request when the page loads in the browser and fetching related records.  But it depends on your UI design.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 14, 2018 11:22 AM