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

  • Home
  • SEARCH
  • 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 4609660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:01:13+00:00 2026-05-22T01:01:13+00:00

Suppose we have created Entities model, what is preferred way to work with it?

  • 0

Suppose we have created Entities model, what is preferred way to work with it? I’m personally couldn’t make up my mind..

  1. Using ModelAdapter :

    public statiс Product[] GetProducts()
    {
            using(Entities ctx = new Entities())
            {
                    return ctx.Product.ToArray();
            }
    }
    
    
    
    Product[] ps = ModelAdapter.GetProducts();
    // ...
    ModelAdapter.UpdateProduct(p);
    
    • looks neat;
    • but, context is created/released a lot sometimes, objects lose contact with context;
  2. Using context in place:

    using(Entities ctx = new Entities())
    {
            Product[] ps = ctx.Product.ToArray();
    
            // ...
    
            ctx.SaveChanges();
    }
    
    • effective
    • but, code becomes messy
  3. Mixed mode, compromise?

  4. Extension methods:

    using(Entities ctx = new Entities())
    {
        Product[] ps = ctx.GetProducts();
        // ...
        ctx.UpdateProduct(p);
    }
    

Actually now, I’m trying approach #4, implementing utility methods as extensions to context. So I can use one context, and make many calls to this context.

  • 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-05-22T01:01:14+00:00Added an answer on May 22, 2026 at 1:01 am

    Generally use anything that fits your needs, that is maintainable and that fits to the complexity of your application. Few points which you should think about:

    • Never share context among requests, use a context per request, per action or per method depending on your needs.
    • If you want to unit test your application you can find that static methods and sometimes also extension methods can be a problem. But testing application with EF is a separate problem.
    • If you want to modify or insert more items in a single unit of work you can find that a context per method is not what you need
    • Many developers like to use the repository pattern to separate access to EF features from the rest of the application. It has its own pros and cons.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Supose I have following entities created from database tables: Person Student Student include Person
I have created a class LeagueMatch . public class LeagueMatch { public string Home
Suppose i have created one .js file name as: MyNoteBook.js. In this .js file
suppose i have created the C# class lib,now if i look on to the
Many tutorials say that when i have to pass data from controller to view
I have been dealing with this for at least two days now. I don't
I've an application that has three layers: 1. data layer: exposes Entity Framework entities
OK, I am mostly a LAMP developer so I am new to the entity
It seems I am unable to find any answers to how to use EAV
It seems I am unable to find any answers to how to use EAV

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.