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

  • Home
  • SEARCH
  • 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 1094527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:59:04+00:00 2026-05-16T23:59:04+00:00

I have a code-first, POCO project in which I am trying to adjust an

  • 0

I have a code-first, POCO project in which I am trying to adjust an existing database so that it syncs up with what EF is expecting, given my existing model.

I have these entities:

public class FlaggedDate
{
    [Key]
    public long scheduledDayID { get; set; }
    [Required]
    public DateTime date { get; set; }
    [StringLength(50)]
    [Required]
    public string dateStatus { get; set; }
    [Required]
    public bool isVisit { get; set; }
    [Required]
    public bool hasAvailableSlots { get; set; }
    [Required]
    public bool hasInterviewsScheduled { get; set; }

    // navigation properties
    public ICollection<ScheduledSchool> scheduledSchool { get; set; }
    public ICollection<Interview> interviews { get; set; }
    public ICollection<PartialDayAvailableBlock> partialDayAvailableBlocks { get; set; }
    public Visit visit { get; set; }
    public ICollection<Event> events { get; set; }
}

and

public class Visit
{
    [Key]
    public long flaggedDateScheduledDayID { get; set; }
    [Required]
    public bool isFullDay { get; set; }

    // navigation property
    public FlaggedDate flaggedDate { get; set; }
}

The relationship between these two is 1 : 0|1 — i.e., FlaggedDate will exist but it may or may not have a corresponding single Visit object.

EF thinks, based on this model, that FlaggedDate should have an extra field, visit_flaggedDateScheduledDayID, which is nullable. I finally realized why: it thinks the Visit field, flaggedDateScheduledDayID, is an identity column. It’s not supposed to be an identity column; it’s supposed to be a foreign key that connects to FlaggedDate.

I think it does this by convention: I remember reading something to the effect that in CTP4, any field that is a single key and is int or long is assumed to be an identity column.

Is there any way I can tell EF that this is NOT an identity column? I tried fiddling with the Fluent API, but it’s a mystery to me, and there are no data annotations that you can use for this.

Or, alternatively, is there any way I can fiddle with the navigation properties to get this to come out right?

  • 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-16T23:59:05+00:00Added an answer on May 16, 2026 at 11:59 pm

    I discovered I can override the identity behavior with this code:

     modelBuilder.Entity<Visit>().Property(v => v.flaggedDateScheduledDayID).StoreGeneratedPattern = System.Data.Metadata.Edm.StoreGeneratedPattern.None;
    

    However, it is still not making it a foreign key. I guess that’s a different question, though. It seems setting the StoreGeneratedPattern to None is the way to override the default behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.