How to build a mapping file for an insert stored procedure using NHibernate 2.1?

As the name suggests, CreateSQLQuery is for queries, not for insert/updates/deletes. Invoking the kind of sproc you describe is possible, but not AFAIK via any Nbernate-supported query mechanism The sproc itself can be included in a mapping file via the database-object tag. The following example is for Sql Server : database-object> This is done by getting Nbernate to create an IDbCommand for you, filling it with parameters, and calling its ExecuteNonQuery method in the usual ADO.NET way : private void SetFooBar(ISession session, string foo, string bar) { var connection = session.

Connection; var implementor = session. GetSessionImplementation(); var driver = implementor.Factory. ConnectionProvider.

Driver; var command = driver. GenerateCommand(CommandType. StoredProcedure, new global::NSqlCommand.

SqlString("SetFooBar"), new global::NSqlTypes. SqlType { global::NSqlTypes.SqlTypeFactory. GetString(32), global::NSqlTypes.SqlTypeFactory.

GetString(32), }); command. Connection = connection; SetParameter(command, 0, "@Foo", foo); SetParameter(command, 1, "@Bar", foo); command.ExecuteNonQuery(); } private void SetParameter(IDbCommand cmd, int index, string name, object value) { IDataParameter param = (IDataParameter) cmd. Parametersindex; param.

ParameterName = name; param. Value = value; }.

As the name suggests, CreateSQLQuery is for queries, not for insert/updates/deletes. Invoking the kind of sproc you describe is possible, but not AFAIK via any Nbernate-supported query mechanism. The sproc itself can be included in a mapping file via the tag.

The following example is for Sql Server : Your code can then invoke the sproc. This is done by getting Nbernate to create an IDbCommand for you, filling it with parameters, and calling its ExecuteNonQuery method in the usual ADO. NET way : private void SetFooBar(ISession session, string foo, string bar) { var connection = session.

Connection; var implementor = session. GetSessionImplementation(); var driver = implementor.Factory. ConnectionProvider.

Driver; var command = driver. GenerateCommand(CommandType. StoredProcedure, new global::NSqlCommand.

SqlString("SetFooBar"), new global::NSqlTypes. SqlType { global::NSqlTypes.SqlTypeFactory. GetString(32), global::NSqlTypes.SqlTypeFactory.

GetString(32), }); command. Connection = connection; SetParameter(command, 0, "@Foo", foo); SetParameter(command, 1, "@Bar", foo); command.ExecuteNonQuery(); } private void SetParameter(IDbCommand cmd, int index, string name, object value) { IDataParameter param = (IDataParameter) cmd. Parametersindex; param.

ParameterName = name; param. Value = value; }.

I am using EntityFramework with Oracle using odp.net. The parameterized sql query does not work. Var set = ctx.Database.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions