in Education by
I have an incoming json object that represents the data pulled from a database structure. I would like to map it to the Entity Framework model which has the definitions either from attributes or from model builder in the DB context. When running Entity Framework, this data maps correctly so I know the models are correct. So using the same structure, instead of calling the database through EF, I am pulling from an API that has the same incoming data structure as the entity.Property column names. How do I map the incoming json structure to the model object? Attributes [Table("model_example")] public class ModelExample { [Column("property_to_map")] // <-- db column name public int PropertyToMap { get; set; } } Or ModelBuilder: modelBuilder.Entity<ModelExample>(entity => { entity.ToTable("model_example"); entity.Property(e => e.PropertyToMap).HasColumnName("property_to_map"); } Incoming JSON example: { "property_to_map":1 } So if this data was pulled from the db it would automatically be mapped to `ModelExample.PropertyToMap' and the ModelExample code model. How do I map it? Is there a way to use the Entity Framework process? Update I know how to map from json to object using Newtonsoft. I'm trying to map to the entity without having to use a mapper. Entity Framework already has these values, I was hoping to just use entity framework tie in. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I've used JsonConvert.DeserializeObject from Newtonsoft to do this in the past. Hopefully this helps. class Example { public int property_to_map {get; set;} } class ApiCalls{ public void MakeApiCall() { var response = ApiCall(); var MappedObject = JsonConvert.Deserialize(response); //Do whatever you need now with the mapped object. } }

Related questions

0 votes
    Department and store model. They are a one to one relationship. when I do the (Include) only some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have two tables. Orders OrderID | UserID | OrderTotal 1 | 1 | 100 2 | 2 | 110 3 | 1 ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I try to create database from entity framework code first follow with this tutorial http://www.asp.net/mvc ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    In dbms, what will be the outcome when we map a multivalued attribute for any entity from the er model to the relational model? Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    I've searched stackoverflow for a proper solution on generating a many-to-many relationship, using EF Core, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I'm using EF code first. By convention, I have added a foreign key and a reference to the foreign ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I want to test my Entities that are built using Entity Framework. My concern is that using Entity Framework ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    What is Database First Approach in MVC using Entity Framework?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    new to play and just trying to follow the video on: http://www.playframework.org/ I'm coming so ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    Which JSON framework is supported by iOS?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    here is my code. var http=require("http"); var fs = require("fs"); var express = require(" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    How many methods exist for normalizing the data? (a) one (b) two (c) three (d) profiler The question ... Analysis of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    How many functions exist for wrangling the data with dplyr package? (a) one (b) seven (c) three (d) ... Data Analysis of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    How many functions exist for tidying the data? (a) one (b) two (c) three (d) four This question was ... Data Analysis of R Programming Select the correct answer from above options...
asked Feb 11, 2022 in Education by JackTerrance
...