Avatar of techsuppoprt

asked on 

Automating LINQ Insert statements

Hi Experts,

I'm a beginner with LINQ so I would appreciate any help.
I'm trying to insert a lot of rows into my database. The obvious way would be to do something like this:

            DestinationDbDataContext newDb = new DestinationDbDataContext();

            var userRole1 = new Role { Name = "Administrator", Description = "Administrator User" };
            var userRole2 = new Role { Name = "Tech", Description = "Technical Support" };
            var userRole3 = new Role { Name = "Sales", Description = "Sales Person" };
            var userRole4 = new Role { Name = "Accounting", Description = "Accounting Department" };


but of course this is not very efficient. Can you help me think of a way to to move LINQ stuff into a separate method so all I'd have to do is to pass the Table name , values and maybe field names and have LINQ handle everything separately.

Thank you in advance!
.NET ProgrammingC#

Avatar of undefined
Last Comment

8/22/2022 - Mon