Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:12:03+00:00 2026-06-13T10:12:03+00:00

I come from the web forms world, and I’m learning MVC4 and Entity Framework

  • 0

I come from the web forms world, and I’m learning MVC4 and Entity Framework 5 with a code-first approach. This is my first time using EF code-first and I’m having some trouble understanding what EF needs from me to be able to create/update a database.

I’m making a request to a RESTful service and deserializing the response into a DataContract. Ideally, I would like to be able to insert this DataContract into a database but I’m unsure how to generate the DbContext classes from the DataContract so EF can do it’s thing.

The simplified version of the DataContract…

[DataContract]
public class MoviesDataContract {
    [DataMember(Name = "total")]
    public int Total { get; set; }

    [DataMember(Name = "movies")]
    public IEnumerable<Movie> Movies { get; set; }

    [DataMember(Name = "link_template")]
    public string LinkTemplate { get; set; }
}

[DataContract]
public class Movie {
    [DataMember(Name = "id")]
    public int Id { get; set; }

    [DataMember(Name = "title")]
    public string Title { get; set; }

    [IgnoreDataMember]
    public int? Year {
        get {
            int i;
            return int.TryParse(_year, out i) ? i : (int?)null;
        } 
        set { _year = value.ToString(); }
    }

    [DataMember(Name = "year")]
    private string _year { get; set; }
}

Here’s an example of the DataContract usage…

using(var response = (HttpWebResponse)request.GetResponse()) {
    var serializer = new DataContractJsonSerializer(typeof (MoviesDataContract));
    var dataContract = (MoviesDataContract)serializer.ReadObject(response.GetResponseStream());

    var model = new List<MovieViewModel>();
    dataContract.Movies.ToList().ForEach(movie => model.Add(new MovieViewModel {
        Title = movie.Title,
        Year = movie.Year
    }));

    // MovieDbContext doesn't exist and it's what I'm unsure of how to generate
    // I would think it would work something like this though (once created)
    var db = new MovieDbContext();
    db.Add(dataContext);
    db.SaveChanges();

    return View(model);
}

My Questions are…

  1. Is there a way to generate the DbContext classes from my DataContract or do I need to manually create them?
  2. Is there a better approach to using (or really saving to a db) Deserialized data with Entity Framework (especially EF5)?
  3. Could someone provide a link that discusses EF (4 or higher) being used in conjunction with a DataContract? I think I may not have a complete grasp on how to effectively use EF5.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:12:04+00:00Added an answer on June 13, 2026 at 10:12 am

    Have you tried feeding your data contracts to DBSet’s like you would when starting a normal code-first project?

    public class ProductContext : DbContext
    
    {
    
        public DbSet<Category> Categories { get; set; }
    
        public DbSet<Product> Products { get; set; }
    
    }
    

    EF should ignore the existing attributes and create some entities.

    See this article for a good example of how to work with DataContext: http://msdn.microsoft.com/en-us/jj729737

    Since you’re new to EF you might as well start here: http://msdn.microsoft.com/en-us/ee712907

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a Web Application using asp.net (C#). I come from windows forms
I come from a .NET background and need to do a web project in
I come from the Java world, so to me it's all object.foo() , but
I come from the asp.net world where we'd use an objectdatasource, hooked up to
I'm trying to use this DataBase that come with this sample project with from
I come from a webforms background, and at this point I'm quite frustrated with
I often come across web applications that expose internal database primary keys through forms
I come from a Java background and am getting more into .NET, what are
I come from ruby/C# and am new to Python. I'm looking at the following
I come from a C++ background and I've been working with C# for about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.