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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:42:43+00:00 2026-06-14T13:42:43+00:00

Supposed I have an entity framework entity named Foo, and in Foo a property

  • 0

Supposed I have an entity framework entity named Foo, and in Foo a property called Bar.

Is there a way in the setter of Bar to get to the entity framework context?

public partial class Foo : IObjectWithChangeTracker
{
    public string Bar
    {
        get { /* ... */ }
        set
        {
            // How do I get the entity context here?
        }
    }

}
  • 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-14T13:42:44+00:00Added an answer on June 14, 2026 at 1:42 pm

    If I understand your question correctly my approach for doing this would be to add properties to Bar that are not under the data contract then write another method that retrieves the other object and set Bars properties there. But I may not understand your question for the reasons HighCore stated. The whole idea doesn’t make sense to me; an object does not own a context.

    if (context.OtherObjectTable != null)
            {
                var otherObj = (from obj
                               in context.OtherObjectTable
                               where obj.Name == "Name/key for obj"
                               select obj).FirstOrDefault(); // ensures we only get one back
    

    If you’re searching by primary key you just remove the FirstOrDefault(). If you can get back multiple results create another loop where you iterate over otherObj (potentially a list now) and filter on the next identifying property. After that loop you can just do normal assignment like

        Bar.Count = (int)otherObj.SomeInt32;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Entity Framework entity with a string Property named Description. Searching for
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
Suppose I have public IList<Entity> Children { get; set; } public NotifyChildren(Func<object, bool> action,
I have the following entity public class Employee { public int EmployeeID { get;
I've been wondering for some time if there is any way in Entity Framework
I have an ASP.NET MVC application which uses Entity Framework to get data. I
I'm trying out Entity Framework Code first CTP4. Suppose I have: public class Parent
Suppose I have an entity object defined as public partial class Article { public
Suppose I have the following 2 entities: @Entity public class Person implements Serializable {
Supposed I have two classes like this: public class Parent { public string Id

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.