none
how to save parent and child list using Ado.net (no EF) RRS feed

  • Question

  • I have parent/child list class,

    public class PointDataClone
    {
        public int DataId { get; set; }
        public string UniqueKey { get; set; }
        public string Description { get; set; }
        public DateTime InsertDateTime { get; set; }
        public int Count { get; set; }
    
        public List<PointToPointData> PointToPointData { get; set; }
    }
    
    public class PointToPointData
    {
        public string UniqueKey { get; set; }
        public DateTime InsertDateTime { get; set; }
    }

    Now I prepare my parent and within it child list like below,

      

    I need to send max 100 parent/child list for saving to database using ado.net. I don't think saving one-by-one record is feasible solution as lots of database call.

    Please suggest best optimal way using C#, ado.net (I m not using EF). Thanks!!!


    • Moved by Kevin Linq Monday, September 12, 2016 2:49 AM
    Sunday, September 11, 2016 6:16 PM

Answers

  • Hi,

    doing row by row inserts for a few hundreds of records is not that exceptional, believe me, it's not in the range of what one would call a bulk insert. The database calls would be quite effecient.

    So i'd suggest you just loop through your records and add them one by one; if you want some bulk method, then you could try concatenate your content in one big string with the necessary separators, send this as a varchar(max) argument to a stored procedure, and in the stored procedure, parse the string back to rows and insert them, but that's a whole other ballgame, with it's own set of problems and pitfalls.

    regards,

    Nico


    Regards, Nico <br/>

    Friday, September 16, 2016 10:12 AM

All replies

  • https://blogs.msdn.microsoft.com/sqlserverstorageengine/2015/09/08/passing-arrays-to-t-sql-procedures-as-json/

    You can find other articles about how to pass in collection and arrays, like using XML.

    Sunday, September 11, 2016 9:18 PM
  • Hi  Yazdani ISTS :

    Thank you for posting here.

    Since your issue is related to ADO.Net , I will move your thread to ADO.net forum . 

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Here is the link of ADO.net forum:https://social.msdn.microsoft.com/Forums/en-US/home?category=dataplatformdev

    If you have anything else regarding C# programming , please feel free to let me know . 

    Best Regards,

    Kevin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, September 12, 2016 2:46 AM
  • Hi,

    doing row by row inserts for a few hundreds of records is not that exceptional, believe me, it's not in the range of what one would call a bulk insert. The database calls would be quite effecient.

    So i'd suggest you just loop through your records and add them one by one; if you want some bulk method, then you could try concatenate your content in one big string with the necessary separators, send this as a varchar(max) argument to a stored procedure, and in the stored procedure, parse the string back to rows and insert them, but that's a whole other ballgame, with it's own set of problems and pitfalls.

    regards,

    Nico


    Regards, Nico <br/>

    Friday, September 16, 2016 10:12 AM