Advertisement

07.23.2008 at 11:38AM PDT, ID: 23589647
[x]
Attachment Details

Automating LINQ Insert statements

Asked by techsuppoprt in Language Integrated Query - LINQ, C# Programming Language

Tags: LINQ, C#

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" };

            newDb.Roles.InsertOnSubmit(userRole1);
            newDb.Roles.InsertOnSubmit(userRole2);
            newDb.Roles.InsertOnSubmit(userRole3);
            newDb.Roles.InsertOnSubmit(userRole4);
            newDb.SubmitChanges();

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!Start Free Trial
[+][-]07.23.2008 at 04:51PM PDT, ID: 22074993

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:43PM PDT, ID: 22076556

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:56PM PDT, ID: 22076605

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Language Integrated Query - LINQ, C# Programming Language
Tags: LINQ, C#
Sign Up Now!
Solution Provided By: naspinski
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628