Pergunta

I'm using Rob Conery's Massive to connect to my database, but I don't seem to be able to be able to save a list of dynamic objects to the database. I thought this was supported though.

Here's the code I am attempting to use:

    int numberOfChildren = int.Parse(Request.Form["numberOfChildren"]);        
    List<dynamic> children = new List<dynamic>();

    for(int i = 1; i <= numberOfChildren; i++) {
        dynamic child = new ExpandoObject();
        child.FamilyID = familyId;
        child.Type = "CHILD";
        child.LastName = Request.Form[i + "-childLastName"];
        child.FirstName = Request.Form[i + "-childFirstName"];
        child.SendSmsAlerts = false;
        child.Gender = Request.Form[i + "-childGender"];
        child.Birthdate = Request.Form[i + "-childBirthdate"];

        children.Add(child);
    }

    var people = new People();
    people.Save(children);

I get a "Parameter count mismatch." error on line 78 of Massive.cs

Everything works fine if i only pass in a single dynamic object at a time, the error is only raised when I attempt to pass in the list. Based on the documentation on GitHub I thought this was supported and it would save all the children in one transaction.

Foi útil?

Solução

Save takes an params array not a list.

people.Save(children.ToArray());
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top