I have an MS-SQL database with a table created using this code
CREATE TABLE [dbo].[portfoliomanager](
[idPortfolioManager] [int] NOT NULL PRIMARY KEY IDENTITY,
[name] [varchar](45) NULL
)
so idPortfolioManager is my primary key as well as auto-increment. Now in my Windows WPF application, I am using NHibernate to help with adding / updating / removing / etc. data from the database. Here is the class that should connect to the portfoliomanager table
namespace PortfolioManager
{
[Class(Table="portfoliomanager",NameType=typeof(PortfolioManagerClass))]
public class PortfolioManagerClass {
[Id(Name = "idPortfolioManager")]
[Generator(1, Class = "identity")]
public virtual int idPortfolioManager { get; set; }
[NHibernate.Mapping.Attributes.Property(Name = "name")]
public virtual string name { get; set; }
public PortfolioManagerClass() {
}
}
}
and some short code to try to insert something
PortfolioManagerClass portfolio = new PortfolioManagerClass();
Portfolio.name = "Brad Portfolios";
The problem is that when I try to run this, I get this error:
{System.Data.SqlClient.SqlException: cannot insert a NULL value in the column 'idPortfolioManager', table 'PortfolioManagementSystem.dbo.portfoliomanager'; column does not allow null. INSERT fails. The application was interrupted ...
with external exception
{ " : [PortfolioManager.PortfolioManagerClass] [SQL: portfoliomanager (name) VALUES (?); SCOPE_IDENTITY()]" }
, , NHibernate, - , . , Class= "native" unsaved-value = "0" . !
Edit:
1, ( , , ), . sql-, , SQL, , NHibernate . , SQL : (