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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:02:50+00:00 2026-06-14T12:02:50+00:00

I have the following: public abstract class EntityBase { [Key] public int Id {

  • 0

I have the following:

   public abstract class EntityBase
   {
      [Key]
      public int Id { get; set; }

      public DateTime? CreatedTime { get; set; }
      public DateTime? ModifiedTime { get; set; }
   }



public class AnalysisFile : EntityBase
   {
      public AnalysisFile()
      {
         DateAdded = DateTime.Now;
      }

      public string SourceFolder { get; set; }
      public string Filename { get; set; }
      public DateTime DateAdded { get; set; }
      public long FileSize { get; set; }
      public Document Document { get; set; }
   }

public class Document : EntityBase
   {
      public Document()
      {
         Publish = true;
      }

      public string Name { get; set; }
      public int AreaId { get; set; }
      public int SchoolId { get; set; }
      public int Year { get; set; }
      public long FileSize { get; set; }
      public AnalysisFile AnalysisFile { get; set; }
      public School School { get; set; }
      public Area Area { get; set; }
      public bool Publish { get; set; }
   }

     modelBuilder.Entity<Document>().HasRequired(x => x.AnalysisFile);
     modelBuilder.Entity<AnalysisFile>().HasOptional(x => x.Document);

My issue is that EF does not appear to create a foreign key for the relationship between AnalysisFile and Document, am I missing something here or is this the expected behavior?

I have also tried creating AnalysisFileId and DocumentId properties on both classes but when I do that they don’t get populated with any ids.

Another question also: how can I ensure that Document has cascade-deletion against AnalysisFile?

  • 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-14T12:02:52+00:00Added an answer on June 14, 2026 at 12:02 pm

    One-to-one relationships with Entity Framework are Shared Primary Key Associations. They don’t have a separate foreign key column aside from the primary key because the primary key in Document is the foreign key to AnalysisFile at the same time. (You can see that when you inspect the relationship created in the database. It should relate the foreign key Id in Document with the primary key Id in AnalysisFile.)

    You can enable cascading delete like so:

    modelBuilder.Entity<Document>()
        .HasRequired(x => x.AnalysisFile)
        .WithOptional(x => x.Document)
        .WillCascadeOnDelete(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class to test: public abstract class Challenge { protected int
I have 3 following classes: public class BaseProperty1{ public string Property1 {get; set;} }
I have following code: public abstract class Operand<T> { public T Value { get;
I have the following entities public abstract class Card { public virtual int Id
I have the following class definitions public abstract class AbstractClass { [Key] public string
I have the following business objects: public abstract class Product { public int Id
I have following classes: public abstract class CustomerBase { public long CustomerNumber { get;
I have the following types: public abstract class Vehicle { public int Id {
I have the following classes: public abstract class Generic(){ private int Id; ... }
I'm looking at some Java classes that have the following form: public abstract class

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.