Mass Inserts

Posts   
 
    
jg
User
Posts: 25
Joined: 29-Dec-2011
# Posted on: 29-Feb-2012 22:51:45   

SQL Server 2008 .Net 4.0 C# LLBLGen version 3.1 Final

I am trying to update a bunch of our legacy pages and rewrite them in .Net C#. I am struggling to find a way to rewrite one of our Stored Procedures using LLBLGen. I know I could still call the stored procedure, but we don't want to do that. Also, I can't mess with the table structure.

Here is the piece of SQL that I need to rewrite in LLBLGen:

insert into AppConfig
select distinct l.LanguageKey, @appGlobalID, ItemKey, DefaultValue
from AppConfigDefaults a
inner join Language l on
    a.LanguageKey = l.LanguageKey
where and l.Deleted = 0

When we create a new object it populates all the AppConfig settings with the default values from the AppConfigDefaults table. It is joining to the Language table to support having multiple languages that could all have different values for these settings.

I did get this to work in LLBLGen, but it is really slow. When I run this in the stored procedure it happens almost instantly, but when I run my LLBLGen code, it takes almost a full minute.

Here is my solution:

EntityCollection<MyAppConfigEntity> appConfigs = new EntityCollection<MyAppConfigEntity>(new MyAppConfigEntityFactory());

foreach (int languageKey in activeLanguages)
{
    EntityCollection<MyAppConfigDefaultEntity> appConfigDefaults = GetAppConfigDefaults(languageKey);
    foreach (MyAppConfigDefaultEntity tempAppConfigDefault in appConfigDefaults)
    {
        MyAppConfigEntity tempAppConfig = new MyAppConfigEntity()
        {
            LanguageKey = languageKey,
            AppGlobalID = appGlobalID,
            ItemKey = tempAppConfigDefault.ItemKey,
            ItemValue = tempAppConfigDefault.DefaultValue ?? tempAppConfigDefault.StandardValue
        };
        appConfigs.Add(tempAppConfig);
    }

    using (DataAdapter adapter = new DataAdapter())
    {
        adapter.SaveEntityCollection(appConfigs);
    }
}

There has to be a more efficient way to accomplish this, but I have no idea how. Any help would be appreciated.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Mar-2012 05:54:34   

Hi jg,

Sorry but we don't support bulk/mass inserts. Here is some reasoning behind that: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=18851&StartAtMessage=0&#105881

If you can live with saving an EntityCollection then that is the way to do it. If not, we recommend you to stay on the store procedure and call it from LLBLGen. Another way could be using other tools for this, like SqlBulkCopy.

David Elizondo | LLBLGen Support Team