Note that there are some explanatory texts on larger screens.

plurals
  1. POEF trying to insert nulls into database for some unknown reason
    primarykey
    data
    text
    <p>For some reason, this piece of code returns the following exception: </p> <pre><code>An error occurred while updating the entries. See the inner exception for details. Inner Exception: Cannot insert the value NULL into column 'Id', table 'aspnet-Webate.dbo.Tasks'; column does not allow nulls. INSERT fails.\r\n The statement has been terminated </code></pre> <p>the variable tasks is a string with this form: </p> <pre><code>(task1, task2, task3, task4) </code></pre> <p>The diagnostics are showing each of those 4 tasks with no problems in the console. none of the array indexes are null or blank</p> <pre><code> string[] taskArr = null; tasks = tasks.Substring(1, tasks.Length - 2); //remove the starting and ending parenthesis tasks = tasks.ToLower(); tasks = tasks.Replace(" ", ""); taskArr = tasks.Split(new char[] { ',' }); foreach (string t in taskArr) { System.Diagnostics.Debug.WriteLine("t="+t); if (t != null &amp;&amp; t != "") { Task task = db.Tasks.Find(t); if (task == null) { task = new Task { Id = t }; db.Tasks.Add(task); } } } try { db.SaveChanges(); //save task changes before trying to save role } catch (Exception e) { throw exception code } </code></pre> <p>Is there any other explanation for why EntityFramework may be trying to insert nulls into the database?</p> <p>Here is the task model:</p> <pre><code>using System; using System.Collections.Generic; public partial class Task { public Task() { this.Roles = new HashSet&lt;Role&gt;(); } public string Id { get; set; } public virtual ICollection&lt;Role&gt; Roles { get; set; } } </code></pre> <p>This class is generated by ADO.NET Entity Data Model functionality of Visual Studio 2012, and there are no other partial implementations of it</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload