I am trying to add an object to my Algolia database using a slightly different structure provided by the documentation so that I don't have to type out the Json object in string format, however I ran into an error stating
Cannot implicitly convert anonymous type to System.Collections.Generic.List
I see the red error message for all of the key/values in the objs variable.
var songIndexHelper = HttpContext.Application.Get("SongIndexHelper") as IndexHelper<SongAlgoliaModel>;
List<JObject> objs = new List<JObject>();
objs = new
{
ApprovalFL = false,
FreeFL = album.FreeFL,
LicenseFL = album.LicenseFL,
AccountInfoID = album.AccountInfoID,
AlbumID = album.AlbumID,
SongID = song.SongID,
BPM = song.BPM,
AccountImageURL = album.AccountInfo.ImageURL,
AccountType = "Artist",
AlbumName = album.AlbumName,
Artist = artist,
FeaturedArtist = songArtistsList,
ImageURL = album.ImageURL,
iTunesURL = album.iTunesURL,
LabelName = album.LabelName,
Title = album.AlbumName,
UserID = album.AccountInfo.UserID,
UploadDate = song.UploadDate,
Duration = song.Duration,
objectID = song.SongID
};
songIndexHelper.AddObjects(objs);
Here's the reference to documentation: https://www.algolia.com/doc/api-reference/api-methods/add-objects/
Edit alternative method however, my formatting of LicenseFL is off
List<JObject> objs = new List<JObject>();
objs.Add(JObject.Parse(@"{""ApprovalFL"":false, ""FreeFL"":" + album.FreeFL + ",""LicenseFL"":" +album.LicenseFL+ "}"));
songIndexHelper.AddObjects(objs);
objsis aList<JObject>B) You are reassigning it an instance of an anonymous type -- which is not a list C) Even if it were a list, it would not be a list ofJObject1) You'd need to convert your anonymous type into aJObject(JObject.FromObject(...)might suffice) 2) You'd need to add that to the list, rather than re-assigning the listLicenseFL. States it is expecting a comma after the StringLicenseFLkey (updated original question)