I have a function to writes a bunch of "ImageSignatures" to a DbContext:
using (var db = new ImageContext())
{
foreach (var file in files)
{
var sig = new ImageSignature
{
FileName = file,
Signature = Signature(file),
};
Console.WriteLine("{0}: {1}", Path.GetFileName(sig.FileName), Sig2Str(sig.Signature));
if (sig.Signature != null)
{
db.Images.Add(sig);
}
}
try
{
records = db.SaveChanges(); // where the heck is this saving to!?
}
...
Where the Signature
property is defined as
[MinLength(420)]
[MaxLength(420)]
[Required]
public sbyte[] Signature { get; set; }
If I put a breakpoint just before I Add the sig
, I can see that it's not null, but a 420 byte array as I expect.
On a later run of the application I try to loop over the ImageSignatures I inserted,
foreach (var img1 in db.Images)
{
var set = new List<string> { img1.FileName };
foreach (var img2 in db.Images)
{
if (Distance(img1.Signature, img2.Signature) < 0.6)
{
set.Add(img2.FileName);
}
}
if (set.Count > 1)
{
dupeSets.Add(set);
}
}
But Signature
is always coming back as null. What happened to it? How did it become null, when it wasn't null when I saved it?