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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:54:40+00:00 2026-05-27T09:54:40+00:00

So, I’m fighting a migraine. I cannot see the solution to this problem. I

  • 0

So, I’m fighting a migraine. I cannot see the solution to this problem.

I have a table named dr405 that is preloaded with data. My application only updates existing rows in the table with information.

I have a service method called Save in this save method I set the state in my context for the given DR405 entity to modified and then call SaveChanges. This works as expected.

Now I’m trying to add in another step where I have a model called DR405files which is a child to DR405 using a 1:N relationship. I want to call a method GetUploadedFiles() that will check a directory thats name matches the dr405 primary key for files, then insert into the table dr405files the file names.

I’ve set up the relationships between the Models in both the classes and in the Database. I’ve even written code that will correctly insert the filenames into dr405files. However, after I run the application once, it throws an Null Reference exception in consecutive runs on p.

Any help would be greatly appreciated

public void Save(DR405DBContext context, dr405 obj) 
        {
            obj.ModDate = DateTime.Now;

            context.Entry(obj).State = EntityState.Modified;

            var uploadedFiles = this.GetUploadedFiles(obj.TangiblePropertyId);
                if (uploadedFiles !=null && uploadedFiles.Count > 0)
                {
                    uploadedFiles.ForEach(p=> {
                        var item = new dr405files { TangiblePropertyId = obj.TangiblePropertyId, FileName = p }; <---Exception Occurs here.
                    if(!obj.dr405files.Contains(item))
                    {
                        var fileItem = new dr405files { TangiblePropertyId = obj.TangiblePropertyId, FileName = p };
                        context.Entry(fileItem).State = fileItem.FileId == 0 ? EntityState.Added : EntityState.Modified;
                    }
                    });

                }           
            context.SaveChanges(); 

        }

public List<String> GetUploadedFiles(String id)
{
    var saveLocation = Path.Combine(DR405Service.SavePath + GetDR405ById(new DR405DBContext(), id).TangiblePropertyId);
    Directory.CreateDirectory(saveLocation);
    return Directory.GetFiles(saveLocation).ToList();
}

public class dr405files
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int FileId { get; set; }
    public String TangiblePropertyId { get; set; }
    public String FileName { get; set; }



}

public class dr405
{
    [Key]
    public String TangiblePropertyId { get; set; }
    public DateTime CreateDate { get; set; }
    public DateTime ModDate { get; set; }
    public String PreparerName { get; set; }
...
}
  • 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-27T09:54:41+00:00Added an answer on May 27, 2026 at 9:54 am

    I was trying to load from obj.dr405files. Which was not instantiated yet. I changed the code to pull from context.dr405files and….Voila!

        var uploadedFiles = this.GetUploadedFiles(obj.TangiblePropertyId);            
            if (uploadedFiles !=null && uploadedFiles.Count > 0)            
            {            
                uploadedFiles.ForEach(p=> {            
                    var item = new dr405files { TangiblePropertyId = obj.TangiblePropertyId, FileName = p }; <---Exception Occurs here.            
                if(!obj.dr405files.Contains(item)) 
    

    New Code

        var uploadedFiles = this.GetUploadedFiles(obj.TangiblePropertyId);
            if (uploadedFiles !=null && uploadedFiles.Count > 0)
            {
                uploadedFiles.ForEach(p=> {
                    var item = context.dr405files.FirstOrDefault(f => f.FileName  == p.Name && f.TangiblePropertyId == obj.TangiblePropertyId );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have this code to decode numeric html entities to the UTF8 equivalent character.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.