Wednesday 20 September 2017

NHibernate Insert Into Table

The answer here is: this is not supported. Check the 13.3. DML-style operations, an extract:
The pseudo-syntax for INSERT statements is: INSERT INTO EntityName properties_list select_statement. Some points to note:
  • Only the INSERT INTO ... SELECT ... form is supported; not the INSERT INTO ... VALUES ... form.
    ...
  • select_statement can be any valid HQL select query
    ...
The idea behind DML is that you do manipulation directly on the DB side. For insertion the values must be there (somewhere).
But there is solution for your case, use the standard way:
var customer = new Customer();
customer.FirstName ...
session.Save(customer);
That's correct approach, and will do what you need
Could be interesting reading: NHibernate – Executable DML

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Blog Archive