Here is the inner exception:
InnerException: System.Data.UpdateException
Message=Entities in 'OrganizerDBEntities.Assignments' participate in
the 'CourseId' relationship. 0 related 'Course' were found.
1 'Course' is expected.`
I have three tables (Folder, Assignment, Course). The Assignment table has a primary key called AssignmentId and a foreign key called CourseId whose 'Allow Nulls' property has been set to true. So this exception is preventing me calling _entities.SaveChanges(); and thus peventing me from adding data to the database.
UPDATE: Thanks to marc, That problem was solved, but another arose:
InnerException: System.Data.UpdateException
Message=An error occurred while updating the entries. See the InnerException for details.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
at System.Data.Objects.ObjectContext.SaveChanges()
at AssignmentOrganizer.App_Data.AssignmentRepository.CreateAssignment(Assignment assignmentToCreate) in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\App_Data\AssignmentRepository.cs:line 19
at AssignmentOrganizer.MainWindow..ctor() in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\MainWindow.xaml.cs:line 54
InnerException: System.Data.EntityCommandCompilationException
Message=An error occurred while preparing the command definition. See the inner exception for details.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
InnerException: System.NotSupportedException
Message=Server-generated keys and server-generated values are not supported by SQL Server Compact.
Source=System.Data.SqlServerCe.Entity
StackTrace:
at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateReturningSql(StringBuilder commandText, DbModificationCommandTree tree, ExpressionTranslator translator, DbExpression returning)
at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateInsertSql(DbInsertCommandTree tree, List`1& parameters, Boolean isLocalProvider)
at System.Data.SqlServerCe.SqlGen.SqlGenerator.GenerateSql(DbCommandTree tree, List`1& parameters, CommandType& commandType, Boolean isLocalProvider)
at System.Data.SqlServerCe.SqlCeProviderServices.CreateCommand(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.SqlServerCe.SqlCeProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
InnerException: