C Sharper
C Sharper

Reputation: 8646

Entity framework Handle procedure returning Json

My Stored procedure returns data in json format. Eg.

{
  "StoryData": [
    {
      "UserStoryId": 141204
     }]
}

How can I take this in json format from Entity frameworkside?

I tried :-

using (MyWizard_ARA_AppEntities context = new MyWizard_ARA_AppEntities())
                {
                    log.Info("Database connected successfully");
                    log.Info("GET_AMBIGUITYANALYSIS_RESULT procedure called");                    
                    return context.GET_AMBIGUITYANALYSIS_RESULT().ToArray();
                }

But it was not giving me proper result.

Please help.

EDIT :-

 public virtual ObjectResult<string> GET_AMBIGUITYANALYSIS_RESULT()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("GET_AMBIGUITYANALYSIS_RESULT");
        }

Upvotes: 1

Views: 588

Answers (1)

Emre Kabaoglu
Emre Kabaoglu

Reputation: 13146

You should deserialize returning json result from GET_AMBIGUITYANALYSIS_RESULT procedure to object;

using (MyWizard_ARA_AppEntities context = new MyWizard_ARA_AppEntities())
{
    log.Info("Database connected successfully");
    log.Info("GET_AMBIGUITYANALYSIS_RESULT procedure called");
    var result = JsonConvert.DeserializeObject<Ambiguityanalysis>(context.GET_AMBIGUITYANALYSIS_RESULT());
    return result;
}

public class StoryData
{
    public int UserStoryId { get; set; }
}

public class Ambiguityanalysis
{
    public List<StoryData> StoryData { get; set; }
}

Upvotes: 1

Related Questions