I'm trying to add a Document Attachment record via an OData Connected Service to a Microsoft Dynamics NAV database in C# (Visual Studio Professional 2017), (see code below):-
string lstrFileName = @"C:\Users\user.name\Documents\PDF\BCTest\Test Attachment 3.pdf";
System.IO.FileInfo lfi = new System.IO.FileInfo(lstrFileName);
NAV.API_Document_Attachment lobjDA = NAV.API_Document_Attachment.CreateAPI_Document_Attachment(5900, "SO000006", "Order", 0, 1);
lobjDA.AttachedDate = DateTime.Now;
lobjDA.FileName = lfi.Name;
lobjDA.FileExtension = lfi.Extension.Replace(".", string.Empty);
lobjDA.FileType = "2";
objContext.AddToAPI_Document_Attachment(lobjDA);
objContext.SaveChanges();
… but when it gets to SaveChanges, I get: "{"error":{"code":"Application_DialogException","message":"Please attach a document first."}}"
How do I programmatically attach a document?