Wednesday 15 July 2015

transactions - NHibernate extract DBTransaction from Session -


I have a legacy DB where some stored proc calculates the line ID for all tables. Now I overwrite the IID attribute generator I want to do as I have been prompted on this page to avoid the ID (X => X.ID). So far, I can save some objects, of course, an ENHIRBNAT transaction, named Appendix Hierarchy, as soon as it comes to ATKIdGenerator. Generate and this command starts. Execute Nano () I need the command to get some ExecuteNonQuery exception when a command is assigned to the command in the pending local transaction. The transaction property of the command has not been started.

How can I attach it to the order to remove the DB transaction from the Nhibernate session object?

I am using Fluentmapping for Poké

  Public addendum hierarchmap () {Table ("Appendix Hierarchy"); ID (x = & x; x.id). GeneratedBy.Custom (ATKIdGenerator), a = & gt; a.AddParam ("TableName", "Appendix Hierarchy")); .....  

And here is the ID generator

  Public category ATKIdGenerator: IIdentifierGenerator, IConfigurable {private string TableName {get; Set; } #region IIdentifierGenerator Member Public Object Generation (NHibernate.Engine.ISessionImplementer session, object obj) {IDbCommand Order = New SqlCommand (); order. Connection = session. Connection; //transaction.Enlist(command); Type the command. Type command = command type Stored procedure; Command. Comma.txt = "dbo.ups_GetNewId"; // Set input parameter var parm = new SqlParameter ("@ tableName", SqlDbType.VarChar); Parm.Value = TableName; Command.Parameters.Add (parm); // set output parameter var outputParameter = new SqlParameter ("@ id", SqlDbType.Int); OutputParameter.Direction = Parameter Direction.optput; Command.Parameters.Add (outputParameter); // Set a return value var return parameter = new SQLParameter ("@RTRN_URAN", SQLDB type.ins); Return Parameter.Direction = Parameter Direction. Return value; Command.Parameters.Add (returnParameter); // execute the stored procedure command.ExecuteNonQuery (); Return (int) ((aclpamer) command. Parameter ["@ id"]). Values; } #interval # Regional Organizer Eligible Member Public Configure Zero (NHibernate.Type.IType Type, IDictionary & lt; String, String & gt; Params, NHibernate.Dialect.Dialect d) {TableName = params ["TableName"]; } I think that you need to open another connection to generate a method, use one on the session. . 


No comments:

Post a Comment