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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:42:19+00:00 2026-05-29T21:42:19+00:00

I have an instance of a class called AccessData, which inherits from DbContext. So

  • 0

I have an instance of a class called AccessData, which inherits from DbContext. So it is an Entity Framework code first context class and looks like this…

public class AccessData : DbContext
{
    public DbSet<apps_Apps> apps_AppsList;
    public DbSet<apps_AppsOld> apps_AppsOldList;
    ...
    //Several other DbSet<> properties
}

Using Reflections, I have identified one of these DbSet properties on the AccessData object like this…

var listField = accessData.GetType().GetField(typeName + "List");

I now need to be able to add objects to this DbSet property.

Given that I only have a FieldInfo object that represents the DbSet field, how do I call the Add method of this particular Field on the AccessData object and pass in an object?

Or in other words how do I call the following?

accessData.<FieldInfoType>.Add(obj);

Hope this makes sense.

  • 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-29T21:42:21+00:00Added an answer on May 29, 2026 at 9:42 pm

    Get the field’s value:

    object fldVal = listField.GetValue(accessData);
    

    Get the MethodInfo for the method you want to invoke:

    MethodInfo addMethod = fldVal.GetType().GetMethod("Add", new Type[] { typeof(obj) });
    

    And invoke it:

    addMethod.Invoke(fldVal, new object[] { obj });
    

    Or if you’re using .NET 4, you may be able to use the new dynamic keyword to simplify the last 2 steps:

    dynamic fldVal = listField.GetValue(accessData);
    fldVal.Add(obj);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Note , which includes an instance variable called time_spent
I have a class called Sprite, and ballSprite is an instance of that class.
In my MIDLet I have an instance of the java class ImageFetcher called anImg.
Assume I have a Model class called Bird and a instance of Bird called
I have a class (simulation) which creates an instance of another class (GUI). Inside
Let's say I have 2 instance of a class called 'Animal'. Animal has 3
I have a data structure (which is a class) called user_class and I want
I have a class called FooJob() which runs on a WCF windows service. This
I have a class called ListViewController which has a UITableView attached to it and
I have an instance of NSNumber * did inside a class called Reservation. Below

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.