This question is locked. New answers and comments are not allowed.
I had used forward mapping to create my classes. My code are as follow:
| IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope(); |
| scope.Transaction.Begin(); |
| ScheduledWorkshop sw = new ScheduledWorkshop(); |
| sw.Id = tbScheduledWorkshopID.Text; |
| sw.Classroom = tbClassroom.Text; |
| sw.Scheduleddatetime = new DateTime(calDate.SelectedDate.Year, calDate.SelectedDate.Month, calDate.SelectedDate.Day, int.Parse(ddlHour.Text), int.Parse(ddlMinutes.Text),0); |
| // The registration datetime is 24 hours before the class commence |
| sw.Registerationenddatetime = sw.Scheduleddatetime.AddHours(-24); |
| sw.Lecturername = tbLecturerName.Text; |
| sw.Maxclasssize = int.Parse(tbMaxClassSize.Text); |
| sw.Status = ddlStatus.Text; |
| sw.Remarks = tbRemarks.Text; |
| sw.Workshopid = ddlWorkshopName.SelectedValue; |
| sw.Lastmodified = DateTime.Now; |
| sw.Lastmodifiedby = "Session User"; |
| scope.Add(sw); |
| scope.Transaction.Commit(); |
In the MSSQL 2008 Express table, scheduledworkshop's id column is a primary but not auto-incr. The orm mapper's auto-inc is unticked.
I get an exception @ the scope.transaction.commit(); line that seem to point that my primary key "id" is null. The Sql seems to show that it had not inserted the primary key value that I had assigned.
Exception:
| Telerik.OpenAccess.Exceptions.DataStoreException was unhandled by user code |
| Message=Insert of '532097884-9' failed: Telerik.OpenAccess.RT.sql.SQLException: Cannot insert the value NULL into column 'id', table 'mdisexperience.dbo.ScheduledWorkshop'; column does not allow nulls. INSERT fails. |
| The statement has been terminated. |
| at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute() |
| at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute() |
| at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes) |
| INSERT INTO [ScheduledWorkshop] ([classroom], [lastmodified], [lastmodifiedby], [lecturername], [maxclasssize], [registerationenddatetime], [remarks], [scheduleddatetime], [status], [workshopid]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| select scope_identity() |
| (set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: Cannot insert the value NULL into column 'id', table 'mdisexperience.dbo.ScheduledWorkshop'; column does not allow nulls. INSERT fails. |
| The statement has been terminated. |
| at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute() |
| at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute() |
| at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes) |
| Source=Telerik.OpenAccess |
| CanRetry=false |
| StackTrace: |
| at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e) |
| at Telerik.OpenAccess.RT.ExceptionWrapper.Throw() |
| at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x) |
| at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.internalCommit(Boolean phase) |
| at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.commit() |
| at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.commit() |
| at Telerik.OpenAccess.RT.TransactionImpl.Commit() |
| at ExperienceManagementSystem.scheduleworkshop.btnAddWorkshop_Click(Object sender, EventArgs e) in C:\Users\Azel\documents\visual studio 2010\Projects\ExperienceManagementSystem\ExperienceManagementSystem\scheduleworkshop.aspx.cs:line 37 |
| at System.Web.UI.WebControls.Button.OnClick(EventArgs e) |
| at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) |
| at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) |
| at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) |
| at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) |
| at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) |
| InnerException: Telerik.OpenAccess.RT.sql.SQLException |
| Message=Cannot insert the value NULL into column 'id', table 'mdisexperience.dbo.ScheduledWorkshop'; column does not allow nulls. INSERT fails. |
| The statement has been terminated. |
| Source=Telerik.OpenAccess.Adonet2 |
| Description=SQLState=;Cannot insert the value NULL into column 'id', table 'mdisexperience.dbo.ScheduledWorkshop'; column does not allow nulls. INSERT fails. |
| The statement has been terminated. |
| ErrorCode=515 |
| Number=515 |
| StackTrace: |
| at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute() |
| at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute() |
| at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes) |
| InnerException: |
I had recreated all the mappings from scratch a few times using the ORM Wizard but the error still persist. What seems to be the errror here?