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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:05:46+00:00 2026-05-24T11:05:46+00:00

I am using Ef 4.1 code first. I am getting the follwing error and

  • 0

I am using Ef 4.1 code first.

I am getting the follwing error and not sure what I am doing wrong:

An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details.

Inner exception:

Invalid column name ‘GrantApplicationIs’.
Invalid column name ‘GrantApplication_Id’.

I have a grant application and I am trying to add an audit entry to it when I save it to the database.

Here is my context:

public class HbfContext : DbContext
{
   public DbSet<Bank> Banks { get; set; }
   public DbSet<AccountType> AccountTypes { get; set; }
   public DbSet<GrantApplication> GrantApplications { get; set; }
   public DbSet<AuditEntry> AuditEntries { get; set; }
}

Grant Application class:

public class GrantApplication
{
   public int Id { get; set; }
   public string EmployeeNumber { get; set; }
   public string Title { get; set; }
   public string FirstName { get; set; }
   public string LastName { get; set; }
   public virtual ICollection<AuditEntry> AuditEntries { get; set; }
}

AuditEntry class:

public class AuditEntry
{
   public int Id { get; set; }
   public int OldValue { get; set; }
   public int NewValue { get; set; }
   public DateTime AuditDate { get; set; }
   public string EmployeeNumber { get; set; }
   public int GrantApplicationIs { get; set; }
   public GrantApplication GrantApplication { get; set; }
}

This is how I add a new audit entry to a new grant application:

public void Insert(GrantApplication grantApplication)
{
   DateTime currentDateTime = DateTime.Now;
   string submitterEmployeeNumber = "123456";

   grantApplication.SignatureDate = currentDateTime;
   grantApplication.SubmitterEmployeeNumber = submitterEmployeeNumber;

   // Add audit entry
   grantApplication.AuditEntries = new List<AuditEntry>();
   grantApplication.AuditEntries.Add(new AuditEntry
   {
      NewValue = grantApplication.GrantApplicationStateId,
      AuditDate = currentDateTime,
      EmployeeNumber = submitterEmployeeNumber
   });

   // Insert the new grant application
   grantApplicationRepository.Insert(grantApplication);
}

UPDATE:

My table structures looks like this:

GrantApplications table:

Id int
EmployeeNumber varchar(6)
Title varchar(10)
FirstName varchar(50)
LastName varchar(50)

AuditEntries table:

Id int
GrantApplicationId int
OldValue int
NewValue int
AuditDate datetime
EmployeeNumber varchar(6)

I have no idea what GrantApplicationIs and GrantApplication_Id and why they are column names. From what?

  • 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-24T11:05:47+00:00Added an answer on May 24, 2026 at 11:05 am

    For me it looks that this is the source of the problem:

    public int GrantApplicationIs { get; set; }
    

    Is this a typo? Shoudn’t it be GrantApplicationId? Anyway the effect is:

    • GrantApplicationIs isn’t recognized as the foreign key property for the GrantApplication navigation property. Instead it’s an ordinary scalar property. If you don’t have a column named like this in the DB you get your first exception: Invalid column name ‘GrantApplicationIs’.

    • EF uses the default name for the FK database column which is GrantApplication_Id. If you don’t have a column named like this in the DB you get your second exception: Invalid column name ‘GrantApplication_Id’.

    Solution:

    • Either name the FK property according to conventions (GrantApplicationId)
    • Or apply data annotations or Fluent API to tell EF that GrantApplicationIs is indeed your FK property (and create an appropriate column in the DB).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parallelise a code using scala actors. That is my first
I have an AXIS2/JAX-WS web service using a code first implementation (yes I know,
I'm using the STL map data structure, and at the moment my code first
I have been using this code with great success to pull out the first
A bit of background first: I am using base code from a remote SVN
I am using the following code to get an alphabetic number of a first
After checking out code for the first time from a repository into Eclipse using
Let me first put the code snippets here. I am just using the ASP.NET
How to get the first child id inside the div using JQuery. Sample code:
This questions involves 2 different implementations of essentially the same code. First, using delegate

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.