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 335719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:10:30+00:00 2026-05-12T10:10:30+00:00

Suppose I have two table tab1, tab2. EF will create a edmx file and

  • 0

Suppose I have two table tab1, tab2. EF will create a edmx file and there are two entities created.

Then I want to add a computer member to tab1, which get some result from tab2, such as count, sum. What I used is partial class:

public partial class tab1{
   public int Count{
      get{
             int cnt;
             //...
             return cnt;
         }
   }
   public int Total{
      get{
             int total;
             //the matching sql like select sum(column) from tab2
             return total;
         }
   }
}

I want to cnt is counts in tab2(so the SQL should be select count(1) from tab2). Or total which is calculated from another table.
But how to implement it? there is no something like datacontext yet.

  • 1 1 Answer
  • 1 View
  • 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-12T10:10:30+00:00Added an answer on May 12, 2026 at 10:10 am

    Yes there is – use the ObjectContext ! That’s your “entry point into all things for Entity Framework.

    You named it when you created the EDMX – it’s the same name that’s used for your Entity Framework connection string. It’s a class in your “mymodel.designer.cs” code-behind file for the EDMX model.

    using(MyModelContext ctx = new MyModelContext())
    {
       tab1 newTab = new tab1();
       // set the properties as you wish
    
       ctx.AddTotab1(newTab);
       ctx.SaveChanges();
    }
    

    If your “tab1” and “tab2” entities are linked in a 1:n fashion (one “tab1” can have multiple “tab2” entries), you’ll find a member of “tab1” of type “EntityCollection” – let’s say this is called “tab2Entities”.

    Now if you want to calculate the number of “tab2” entries for a given “tab1” object, just use this code:

    if(!tab2Entities.IsLoaded())
       tab2Entities.Load();
    
    int count = tab2Entities.Count;
    

    That’s all there is! 🙂

    Marc

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

Sidebar

Ask A Question

Stats

  • Questions 162k
  • Answers 162k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Adding session.loop after session.exec allows the program to wait for… May 12, 2026 at 12:05 pm
  • Editorial Team
    Editorial Team added an answer With NSURLRequest / NSMutableURLRequest you can set up authentication using… May 12, 2026 at 12:05 pm
  • Editorial Team
    Editorial Team added an answer The components are painted at the "(0,0)" position for each… May 12, 2026 at 12:05 pm

Related Questions

Suppose I have two tables that are linked (one has a foreign key to
Suppose I have two .NET DataTables populated as follows, where ID is the primary
Now I have seen this question in another forum but it didn't had an
What is the SQL command to copy a table from one database to another
Currently I am working on the design of my degree project. Some days ago

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.