Hello;
I am using NHibernate 2.0.1.GA and I have following problem:
I've created custom stored procedure (InsertAddress), it's job is simple, just inserting data into table (Address).
In mapping file for class (Address) I used <sql-insert> tag and I call that procedure there: [exec InsertAddress @Street=?, @City=?, @State=?].
After calling:
Address a1 = new Address("Street_val", "City_val", "State_val");
...
session.Save(a1)
I get following error:
NHibernate: exec InsertAddress @Street=@p0, @City=@p1, @State=@p2;
@p0 = 'Street_val', @p1 = 'City_val', @p2 = 'State_val', @p3 = ''
System.Data.SqlClient.SqlException: The parameterized query '(@p0 nvarchar(5),@p1 nvarchar(6),@p2 nvarchar(2),@p3 int)exec In' expects the parameter '@p3', which was not supplied.
NHibernate.Exceptions.GenericADOException: could not insert: [Address][SQL: exec InsertAddress @Street=?, @City=?, @State=?]
Why is NHibernate trying to pass param 'p3' to stored procedure?
-----------------------------
Class (C#):
public class Address
{
public virtual int IDAddress { get; set; }
public virtual string Street { get; set; }
public virtual string City { get; set; }
public virtual string State { get; set; }
public Address()
{
}
public Address(string Street, string City, string State)
{
this.Street = Street;
this.City = City;
this.State = State;
}
}
-----------------------------
Mapping file:
...
<class name="Address" table="Address">
<id name="IDAddress" column="IDAddress">
<generator class="identity"/>
</id>
<property name="Street" column="Street"/>
<property name="City" column="City"/>
<property name="State" column="State"/>
<sql-insert >exec InsertAddress @Street=?, @City=?, @State=?</sql-insert>
</class>
...
-----------------------------
DB scripts(MSSQL 2005)
Table Address:
create table Address (
IDAddress INT IDENTITY NOT NULL,
Street NVARCHAR(255) null,
City NVARCHAR(255) null,
State NVARCHAR(255) null,
primary key (IDAddress)
)
Stored procedure:
CREATE PROCEDURE [InsertAddress]
(
@Street nvarchar(255),
@City nvarchar(255),
@State nvarchar(255)
)
AS
INSERT INTO Address (Street, City, State)
VALUES (@Street, @City, @State)
RETURN
|