This topic demonstrates creating a method in Entity Developer NHibernate model, which will execute a parameterized INSERT statement for inserting a row into a table.
For this, perform the following steps:
1. | In the Model Explorer context menu select the Add submenu and then select New Method, or click the corresponding button on the Model Explorer toolbar or on the main application toolbar. |
2. | In the Method Editor dialog specify the SQL for the method: |
3. | Customize the parameters: |
4. | Click OK. |
The method is created.
As a result of the code generation for the model, the following method is generated:
C#:
public static void InsertIntoDepartment(NHibernate.ISession session, System.Nullable<int> DeptNO, string DName, string Loc)
{
NHibernate.IQuery query = session.GetNamedQuery(@"InsertIntoDepartment");
query.SetParameter(@"DeptNO", DeptNO);
query.SetParameter(@"DName", DName);
query.SetParameter(@"Loc", Loc);
query.List();
}
Visual Basic:
Public Shared Sub InsertIntoDepartment ( _
session As NHibernate.ISession, DeptNO As System.Nullable(Of Integer), DName As String, Loc As String)
Dim query As NHibernate.IQuery = session.GetNamedQuery("InsertIntoDepartment")
query.SetParameter("DeptNO", DeptNO)
query.SetParameter("DName", DName)
query.SetParameter("Loc", Loc)
query.List()
End Sub
Now it is possible to use this query in the application with the help of method wrapper. This allows working with the query with all possible convenience, as wrapper methods are strongly typed, are found by IntelliSense and have the corresponding signature.