I get the following ArgumentNullException
when I insert a rather simple entity into a table.
I don't think it matters, but the database is an SQL Server Compact .sdf file.
Value cannot be null. Parameter name: source
at System.Linq.Enumerable.Any[TSource](IEnumerable
1 source, Func
2 predicate)
at System.Data.Entity.Internal.InternalContext.WrapUpdateException(UpdateException updateException)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
at System.Data.Entity.DbContext.SaveChanges()
{{ the code below }}
Here is the code that I'm using:
var newMaterial = _localJobs.DbMaterials.Create();
newMaterial.JobID = a_job.ID;
newMaterial.MaterialName = material.Name;
newMaterial.UseType = material.UseType;
newMaterial.Length = material.Length;
newMaterial.Width = material.Width;
newMaterial.Thickness = material.Thickness;
newMaterial.DefaultLength = material.DefaultLength;
newMaterial.DefaultWidth = material.DefaultWidth;
newMaterial.DefaultThickness = material.DefaultThickness;
_localJobs.DbMaterials.Add(newMaterial);
_localJobs.SaveChanges(); // <- The exception occurs here.
I am properly populating every field with valid data. The only key herein is JobID
. It is a foreign key GUID with an explicit relation with a table called Job
. The proper record already exists in the database.
Here is my table schema.