daelmo wrote:
Ok. Here is the solution we are proposing: attached is a zip file that contains two folders: \driver and \templates. To make it work, follow these steps:
Installation
1. Unzip everything in a temp folder.
2. Open the \driver\MySqlServerDBDriver\MySqlServerDBDriver.csproj, fix the references and compile it.
3. Place the compiled assembly and driver.config into <LLBLGen installation folder>\Drivers\MySqlServer\ (note that MySqlServer is a new folder but you can name it as you want).
4. Place the contents of \template folder into your preferred folder where you store your additional templates. For instance C:\MyCustomLLBLGenTemplates.
Project creation
5. Create a new LLBLGen project. Add a "New Relational Model From a Database". Select the driver that says "SQL Server 2000/2005 ... With Custom Sequences" which is our custom driver, then finish the wizard.
6. Select your special entity that you want to use IDENT_CURRENT. Go to the Mappings sub-tab and select **IDENT_CURRENT **for the identity column.
7. Go to Project->Settings->General and set the "Additional templates folder" setting to C:\MyCustomLLBLGenTemplates. This will made possible to LLBLGen to locate the new custom templates.
Code Generation
8. Hit [F7] (Generate code).
9. At that wizard, click on "Advance" button. Then go to "Template bindings" subtab, then locate the "SD.TemplateBindings.SharedTemplates.NET20.CustomSequences" binding and move it up to the top of the list. This will make that LLBLGen to prefer your new **SD_PersistenceInfoProviderTemplate **over the original one. Then finish the generation wizard.
Some advantages of this approach:
- You don't have to modify anything in your generated code over and over.
- You don't have to worry if you update the LLBLGen built-in templates by re-installing it. The only template you are overriding is SD_PersistenceInfoProviderTemplate, so you just have to look whether or not there is a major change in this template. If it's then incorporate the changes in the template. The template is tiny, so you won't face any extreme task here.
- You can still use the other sequence values (SCOPE_IDENTITY, @@IDENTITY).
- You can share those files/steps with your colleagues.
I tested the files, and they seem to work well, this is an example of a Northwind's Order insert:
INSERT INTO [Northwind].[dbo].[Orders] ([OrderDate]) VALUES (@p1) ;SELECT @p2=IDENT_CURRENT('Northwind.dbo.Orders')
Parameter: @p1 : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 6/30/2012 1:46:00 AM.
Parameter: @p2 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Output. Value: <undefined value>.
Let us know how it works on your side
I took your advice and when I looked inside my PersistenceInfoProvider.cs file, I saw that the identityValueSequenceName was something like:
IDENT_CURRENT('DB.SCHEMA.TABLE')
I was saving a new record, and I got the error:
An exception was caught during the execution of an action query: Invalid object name 'IDENT_CURRENT('DB.SCHEMA.TABLE')'
And the beginning of the query executed looks like:
Query: SELECT @p4 =NEXT VALUE FOR [IDENT_CURRENT('DB].[SCHEMA].[TABLE')]; INSERT INTO [DB].[SCHEMA].[TABLE] ...
There were brackets inserted into the object name, from DB.SCHEMA.TABLE to DB].[SCHEMA].[TABLE and I don't understand why this is and it makes me think this is part of my problem.
Then I tried to add brackets to the object name so it looks like IDENT_CURRENT('[DB.SCHEMA.TABLE]') to get IDENT_CURRENT('[DB].[SCHEMA].[TABLE]'), but then I get a different error:
Unclosed quotation mark after the character string ')]; INSERT INTO [DB].[SCHEMA].[TABLE] ... when the query executed looks like Query: SELECT @p4 =NEXT VALUE FOR [IDENT_CURRENT('[DB].[SCHEMA].[TABLE]')]; INSERT INTO [DB].[SCHEMA].[TABLE]
and I don't understand why that error is coming up because the quotes are matched up in the query