FransBouma / Massive

A small, happy, dynamic MicroORM for .NET that will love you forever.
Other
1.8k stars 323 forks source link

Is the result supposed to be a KeyValuePair? #325

Closed herbertmilhomme closed 6 years ago

herbertmilhomme commented 6 years ago

I don't understand. I thought the end results were supposed to register the database values into the class so i can make calls like an enum function.

I'm looking for results like the first one, StronglyTyped by Jeremy. I got a response back from him on git and he told me that i should look into massive as an alternative to what he started as a prototype. But it doesn't feel the same, and the results don't look anywhere near what i was expecting them to be. I just need a bit of clarification on if Massive can perform the same job if not better than what StronglyTyped was supposed to do/be.

    //var data = Massive.DB.Current.Query(sql);
    //var data = Massive.DynamicModel.Open("DBServer1").Query(sql); 
    var data = new Massive.DynamicModel("DBServer1").Query(sql);
    Response.ContentType = "application/json";
    Json.Write(data, Response.Output);

each gave me the same:

[[{"Key":"Id","Value":1},{"Key":"StatusTitle","Value":"Inprogress"},{"Key":"StatusId","Value":7},{"Key":"Media","Value":"Website"}...

Normally, what i'd get without any extension service:

[{"Id":1,"StatusTitle":"Inprogress","StatusId":7,"Media":"Website"...

However, i'm hoping for there's a solution here.

FransBouma commented 6 years ago

Massive uses Expando's (which are dictionaries) as types for its objects, and therefore there are no strongly typed properties so serialization to json will result in what you got and never in what you expected in your post: you can only get that if you serialize a strongly typed POCO to json, which isn't going to work with Massive as it doesn't use strongly typed poco's but expandos (dynamic types)