Hi Markus
the problem is the Identity PK. See here:
http://www.castleproject.org/ActiveRecord/documentation/trunk/usersguide/pks.html#identity

Try using a GuidComb or HiLo and you'll see no database calls at all with
FlushAction.Never

-Markus

2009/10/16 Markus <[email protected]>

>
> Hi all!
>
> I experience a problem when using SessionScopes and the latest AR 2.0.
> Using MS SQL Server Profiler I found an issue when using a
> SessionScope with FlushAction.Never. To illustrate the problem I
> created a simple Customer class that just a Name property (besides the
> primary key).
>
> Using these lines of code:
>
> using (new SessionScope())
> {
>   var c = new Customer { Name = "ALFKI" };
>   c.Save();
>   c = new Customer { Name = "DUMMY" };
>   c.Save();
> }
>
> in order to create two customers in the database, the SQL Server
> Profiler shows me these SQL statements:
>
> Audit Login
> BEGIN TRANSACTION
> exec sp_executesql N'INSERT INTO Customers (Name) VALUES (@p0); select
> SCOPE_IDENTITY()',N'@p0 varchar(5)',@p0=N'ALFKI'
> exec sp_executesql N'INSERT INTO Customers (Name) VALUES (@p0); select
> SCOPE_IDENTITY()',N'@p0 nvarchar(5)',@p0=N'DUMMY'
> COMMIT TRANSACTION
> Audit Logout
>
>
> Now using the same code from above but this time passing
> FlushAction.Never to the SessionScope constructor leads to the
> following SQL:
>
> exec sp_reset_connection
> Audit Login
> exec sp_executesql N'INSERT INTO Customers (Name) VALUES (@p0); select
> SCOPE_IDENTITY()',N'@p0 nvarchar(5)',@p0=N'ALFKI'
> Audit Logout
> exec sp_reset_connection
> Audit Login
> exec sp_executesql N'INSERT INTO Customers (Name) VALUES (@p0); select
> SCOPE_IDENTITY()',N'@p0 nvarchar(5)',@p0=N'DUMMY'
> Audit Logout
>
>
> As you can see, two logins were executed for each INSERT - which I
> think is not a desirable behaviour. Is there a fix for that issue?
>
>
> Best Regards
>
> Markus
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to