I have the following situation: i need to create some temporary tables to optimize a load problem the recently has ocurred. It seems that LINQ to SQL doesn't work well with temporary table, unless they are mapped on the DBML. I, honestly, still don't understand how scope works on LINQ to SQL. With that in mind i went to define every temporary table on the DBML.
But, as always, things can't be that easy. I can't define on compilation time (which is what linq needs) what name my temporary table will have, because it will be defined when an user logs on the system. To add more: i will have several of these dynamic temporary table, so there's no way i can map it all to the DBML.
When i tried to create my temporary tables through executeCommand
, select its results and cast it to strong type (TempTableDefinition
). However, when i tried to insert values on this new created temporary table i got a SQLException saying 'Invalid object name #NewTempTable' (this was the same name i used to create the table).
It appears that i will have to use pure old plain ADO.NET to create every temporary table and map it's properties to a strong typed object (i prefer this approach). I really wouldn't like to mix ADO.NET with LINQ, since i just read that it's a bad ideia. Plus, i prefer linq approach of strong type objects to the ADO.NET way.
Resume: So, do you know or is it even possible to create dynamic temporary tables that linq to sql can work with? I can't define it's name on compilation time, only on execution time. Any tips will be appreciated.